213 #ifndef NK_SINGLE_FILE 214 #define NK_SINGLE_FILE 217 #ifndef NK_NUKLEAR_H_ 218 #define NK_NUKLEAR_H_ 230 #define NK_UNDEFINED (-1.0f) 231 #define NK_UTF_INVALID 0xFFFD 232 #define NK_UTF_SIZE 4 234 #define NK_INPUT_MAX 16 236 #ifndef NK_MAX_NUMBER_BUFFER 237 #define NK_MAX_NUMBER_BUFFER 64 239 #ifndef NK_SCROLLBAR_HIDING_TIMEOUT 240 #define NK_SCROLLBAR_HIDING_TIMEOUT 4.0f 251 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L)) 252 #define NK_API static inline 253 #elif defined(__cplusplus) 254 #define NK_API static inline 256 #define NK_API static 259 #define NK_API extern 263 #ifdef NK_SINGLE_FILE 264 #define NK_LIB static 266 #define NK_LIB extern 270 #define NK_INTERN static 271 #define NK_STORAGE static 272 #define NK_GLOBAL static 274 #define NK_FLAG(x) (1 << (x)) 275 #define NK_STRINGIFY(x) #x 276 #define NK_MACRO_STRINGIFY(x) NK_STRINGIFY(x) 277 #define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2 278 #define NK_STRING_JOIN_DELAY(arg1, arg2) NK_STRING_JOIN_IMMEDIATE(arg1, arg2) 279 #define NK_STRING_JOIN(arg1, arg2) NK_STRING_JOIN_DELAY(arg1, arg2) 282 #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__COUNTER__) 284 #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__) 287 #ifndef NK_STATIC_ASSERT 288 #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1] 293 #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__COUNTER__) 295 #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__LINE__) 299 #define NK_MIN(a,b) ((a) < (b) ? (a) : (b)) 300 #define NK_MAX(a,b) ((a) < (b) ? (b) : (a)) 301 #define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i)) 303 #ifdef NK_INCLUDE_STANDARD_VARARGS 304 #if defined(_MSC_VER) && (_MSC_VER >= 1600) 306 #define NK_PRINTF_FORMAT_STRING _Printf_format_string_ 308 #define NK_PRINTF_FORMAT_STRING 310 #if defined(__GNUC__) 311 #define NK_PRINTF_VARARG_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, fmtargnumber+1))) 312 #define NK_PRINTF_VALIST_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, 0))) 314 #define NK_PRINTF_VARARG_FUNC(fmtargnumber) 315 #define NK_PRINTF_VALIST_FUNC(fmtargnumber) 326 #ifdef NK_INCLUDE_FIXED_TYPES 328 #define NK_INT8 int8_t 329 #define NK_UINT8 uint8_t 330 #define NK_INT16 int16_t 331 #define NK_UINT16 uint16_t 332 #define NK_INT32 int32_t 333 #define NK_UINT32 uint32_t 334 #define NK_SIZE_TYPE uintptr_t 335 #define NK_POINTER_TYPE uintptr_t 341 #define NK_UINT8 unsigned char 344 #define NK_INT16 signed short 347 #define NK_UINT16 unsigned short 350 #if defined(_MSC_VER) 351 #define NK_INT32 __int32 353 #define NK_INT32 signed int 357 #if defined(_MSC_VER) 358 #define NK_UINT32 unsigned __int32 360 #define NK_UINT32 unsigned int 364 #if defined(_WIN64) && defined(_MSC_VER) 365 #define NK_SIZE_TYPE unsigned __int64 366 #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) 367 #define NK_SIZE_TYPE unsigned __int32 368 #elif defined(__GNUC__) || defined(__clang__) 369 #if defined(__x86_64__) || defined(__ppc64__) 370 #define NK_SIZE_TYPE unsigned long 372 #define NK_SIZE_TYPE unsigned int 375 #define NK_SIZE_TYPE unsigned long 378 #ifndef NK_POINTER_TYPE 379 #if defined(_WIN64) && defined(_MSC_VER) 380 #define NK_POINTER_TYPE unsigned __int64 381 #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) 382 #define NK_POINTER_TYPE unsigned __int32 383 #elif defined(__GNUC__) || defined(__clang__) 384 #if defined(__x86_64__) || defined(__ppc64__) 385 #define NK_POINTER_TYPE unsigned long 387 #define NK_POINTER_TYPE unsigned int 390 #define NK_POINTER_TYPE unsigned long 430 struct nk_draw_command;
438 struct nk_draw_vertex_layout_element;
442 struct nk_style_slide;
544 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 651 #ifdef NK_INCLUDE_COMMAND_USERDATA 1200 #define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c)) 1201 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 1277 NK_API const struct nk_draw_command* nk__draw_next(
const struct nk_draw_command*,
const struct nk_buffer*,
const struct nk_context*);
1291 #define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) 2782 #define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) 2799 #define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) 2842 #define nk_tree_image_push(ctx, type, img, title, state) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) 2862 #define nk_tree_image_push_id(ctx, type, img, title, state, id) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) 2940 #define nk_tree_element_push(ctx, type, title, state, sel) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) 2941 #define nk_tree_element_push_id(ctx, type, title, state, sel, id) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) 3021 #ifdef NK_INCLUDE_STANDARD_VARARGS 3022 NK_API void nk_labelf(
struct nk_context*,
nk_flags, NK_PRINTF_FORMAT_STRING
const char*, ...) NK_PRINTF_VARARG_FUNC(3);
3024 NK_API void nk_labelf_wrap(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*,...) NK_PRINTF_VARARG_FUNC(2);
3025 NK_API void nk_labelf_colored_wrap(struct
nk_context*, struct
nk_color, NK_PRINTF_FORMAT_STRING const
char*,...) NK_PRINTF_VARARG_FUNC(3);
3026 NK_API void nk_labelfv(struct
nk_context*,
nk_flags, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(3);
3028 NK_API void nk_labelfv_wrap(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3029 NK_API void nk_labelfv_colored_wrap(struct
nk_context*, struct
nk_color, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(3);
3032 NK_API void nk_value_uint(struct
nk_context*, const
char *prefix,
unsigned int);
3335 NK_API double nk_propertyd(
struct nk_context*,
const char *name,
double min,
double val,
double max,
double step,
float inc_per_pixel);
3451 #ifdef NK_INCLUDE_STANDARD_VARARGS 3452 NK_API void nk_tooltipf(
struct nk_context*, NK_PRINTF_FORMAT_STRING
const char*, ...) NK_PRINTF_VARARG_FUNC(2);
3453 NK_API void nk_tooltipfv(struct
nk_context*, NK_PRINTF_FORMAT_STRING const
char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3819 struct nk_user_font_glyph;
3822 struct nk_user_font_glyph *glyph,
3825 #if defined(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) || defined(NK_INCLUDE_SOFTWARE_FONT) 3826 struct nk_user_font_glyph {
3831 float width, height;
3845 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 3853 #ifdef NK_INCLUDE_FONT_BAKING 3854 enum nk_font_coord_type {
3860 struct nk_baked_font {
3863 float ascent, descent;
3873 struct nk_font_config {
3874 struct nk_font_config *next;
3883 unsigned char ttf_data_owned_by_atlas;
3885 unsigned char merge_mode;
3887 unsigned char pixel_snap;
3889 unsigned char oversample_v, oversample_h;
3891 unsigned char padding[3];
3895 enum nk_font_coord_type coord_type;
3901 struct nk_baked_font *font;
3905 struct nk_font_config *n;
3906 struct nk_font_config *p;
3909 struct nk_font_glyph {
3912 float x0, y0, x1, y1, w, h;
3913 float u0, v0, u1, v1;
3917 struct nk_font *next;
3919 struct nk_baked_font info;
3921 struct nk_font_glyph *glyphs;
3922 const struct nk_font_glyph *fallback;
3925 struct nk_font_config *config;
3928 enum nk_font_atlas_format {
3929 NK_FONT_ATLAS_ALPHA8,
3930 NK_FONT_ATLAS_RGBA32
3933 struct nk_font_atlas {
3945 struct nk_font_glyph *glyphs;
3946 struct nk_font *default_font;
3947 struct nk_font *fonts;
3948 struct nk_font_config *config;
3958 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 3959 NK_API void nk_font_atlas_init_default(
struct nk_font_atlas*);
3963 NK_API void nk_font_atlas_begin(
struct nk_font_atlas*);
3964 NK_API struct nk_font_config nk_font_config(float pixel_height);
3965 NK_API struct nk_font *nk_font_atlas_add(
struct nk_font_atlas*,
const struct nk_font_config*);
3966 #ifdef NK_INCLUDE_DEFAULT_FONT 3967 NK_API struct nk_font* nk_font_atlas_add_default(
struct nk_font_atlas*,
float height,
const struct nk_font_config*);
3969 NK_API struct nk_font* nk_font_atlas_add_from_memory(
struct nk_font_atlas *atlas,
void *memory,
nk_size size,
float height,
const struct nk_font_config *config);
3970 #ifdef NK_INCLUDE_STANDARD_IO 3971 NK_API struct nk_font* nk_font_atlas_add_from_file(
struct nk_font_atlas *atlas,
const char *file_path,
float height,
const struct nk_font_config*);
3973 NK_API struct nk_font *nk_font_atlas_add_compressed(
struct nk_font_atlas*,
void *memory,
nk_size size,
float height,
const struct nk_font_config*);
3974 NK_API struct nk_font* nk_font_atlas_add_compressed_base85(
struct nk_font_atlas*,
const char *data,
float height,
const struct nk_font_config *config);
3975 NK_API const void* nk_font_atlas_bake(
struct nk_font_atlas*,
int *width,
int *height,
enum nk_font_atlas_format);
3977 NK_API const struct nk_font_glyph* nk_font_find_glyph(
struct nk_font*,
nk_rune unicode);
3978 NK_API void nk_font_atlas_cleanup(
struct nk_font_atlas *atlas);
3979 NK_API void nk_font_atlas_clear(
struct nk_font_atlas*);
4063 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 4093 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 4162 #ifndef NK_TEXTEDIT_UNDOSTATECOUNT 4163 #define NK_TEXTEDIT_UNDOSTATECOUNT 99 4166 #ifndef NK_TEXTEDIT_UNDOCHARCOUNT 4167 #define NK_TEXTEDIT_UNDOCHARCOUNT 999 4234 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 4324 #ifdef NK_INCLUDE_COMMAND_USERDATA 4460 unsigned short w,
unsigned short h,
nk_handle callback_data);
4496 NK_API void nk_stroke_curve(
struct nk_command_buffer*,
float,
float,
float,
float,
float,
float,
float,
float,
float line_thickness,
struct nk_color);
4575 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 4590 enum nk_draw_list_stroke {
4597 enum nk_draw_vertex_layout_attribute {
4601 NK_VERTEX_ATTRIBUTE_COUNT
4604 enum nk_draw_vertex_layout_format {
4614 NK_FORMAT_COLOR_BEGIN,
4615 NK_FORMAT_R8G8B8 = NK_FORMAT_COLOR_BEGIN,
4616 NK_FORMAT_R16G15B16,
4617 NK_FORMAT_R32G32B32,
4621 NK_FORMAT_R16G15B16A16,
4622 NK_FORMAT_R32G32B32A32,
4623 NK_FORMAT_R32G32B32A32_FLOAT,
4624 NK_FORMAT_R32G32B32A32_DOUBLE,
4628 NK_FORMAT_COLOR_END = NK_FORMAT_RGBA32,
4632 #define NK_VERTEX_LAYOUT_END NK_VERTEX_ATTRIBUTE_COUNT,NK_FORMAT_COUNT,0 4633 struct nk_draw_vertex_layout_element {
4634 enum nk_draw_vertex_layout_attribute attribute;
4635 enum nk_draw_vertex_layout_format format;
4639 struct nk_draw_command {
4640 unsigned int elem_count;
4646 #ifdef NK_INCLUDE_COMMAND_USERDATA 4651 struct nk_draw_list {
4653 struct nk_vec2 circle_vtx[12];
4660 unsigned int element_count;
4661 unsigned int vertex_count;
4662 unsigned int cmd_count;
4665 unsigned int path_count;
4666 unsigned int path_offset;
4671 #ifdef NK_INCLUDE_COMMAND_USERDATA 4677 NK_API void nk_draw_list_init(
struct nk_draw_list*);
4681 #define nk_draw_list_foreach(cmd, can, b) for((cmd)=nk__draw_list_begin(can, b); (cmd)!=0; (cmd)=nk__draw_list_next(cmd, b, can)) 4682 NK_API const struct nk_draw_command* nk__draw_list_begin(
const struct nk_draw_list*,
const struct nk_buffer*);
4683 NK_API const struct nk_draw_command* nk__draw_list_next(
const struct nk_draw_command*,
const struct nk_buffer*,
const struct nk_draw_list*);
4684 NK_API const struct nk_draw_command* nk__draw_list_end(
const struct nk_draw_list*,
const struct nk_buffer*);
4687 NK_API void nk_draw_list_path_clear(
struct nk_draw_list*);
4688 NK_API void nk_draw_list_path_line_to(
struct nk_draw_list*,
struct nk_vec2 pos);
4689 NK_API void nk_draw_list_path_arc_to_fast(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
int a_min,
int a_max);
4690 NK_API void nk_draw_list_path_arc_to(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
float a_min,
float a_max,
unsigned int segments);
4691 NK_API void nk_draw_list_path_rect_to(
struct nk_draw_list*,
struct nk_vec2 a,
struct nk_vec2 b,
float rounding);
4692 NK_API void nk_draw_list_path_curve_to(
struct nk_draw_list*,
struct nk_vec2 p2,
struct nk_vec2 p3,
struct nk_vec2 p4,
unsigned int num_segments);
4693 NK_API void nk_draw_list_path_fill(
struct nk_draw_list*,
struct nk_color);
4694 NK_API void nk_draw_list_path_stroke(
struct nk_draw_list*,
struct nk_color,
enum nk_draw_list_stroke closed,
float thickness);
4698 NK_API void nk_draw_list_stroke_rect(
struct nk_draw_list*,
struct nk_rect rect,
struct nk_color,
float rounding,
float thickness);
4700 NK_API void nk_draw_list_stroke_circle(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
struct nk_color,
unsigned int segs,
float thickness);
4702 NK_API void nk_draw_list_stroke_poly_line(
struct nk_draw_list*,
const struct nk_vec2 *pnts,
const unsigned int cnt,
struct nk_color,
enum nk_draw_list_stroke,
float thickness,
enum nk_anti_aliasing);
4705 NK_API void nk_draw_list_fill_rect(
struct nk_draw_list*,
struct nk_rect rect,
struct nk_color,
float rounding);
4708 NK_API void nk_draw_list_fill_circle(
struct nk_draw_list*,
struct nk_vec2 center,
float radius,
struct nk_color col,
unsigned int segs);
4713 NK_API void nk_draw_list_add_text(
struct nk_draw_list*,
const struct nk_user_font*,
struct nk_rect,
const char *text,
int len,
float font_height,
struct nk_color);
4714 #ifdef NK_INCLUDE_COMMAND_USERDATA 4715 NK_API void nk_draw_list_push_userdata(
struct nk_draw_list*,
nk_handle userdata);
5165 #ifndef NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 5166 #define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 16 5168 #ifndef NK_CHART_MAX_SLOT 5169 #define NK_CHART_MAX_SLOT 4 5267 #ifndef NK_WINDOW_MAX_NAME 5268 #define NK_WINDOW_MAX_NAME 64 5380 #ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE 5381 #define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 5384 #ifndef NK_FONT_STACK_SIZE 5385 #define NK_FONT_STACK_SIZE 8 5388 #ifndef NK_STYLE_ITEM_STACK_SIZE 5389 #define NK_STYLE_ITEM_STACK_SIZE 16 5392 #ifndef NK_FLOAT_STACK_SIZE 5393 #define NK_FLOAT_STACK_SIZE 32 5396 #ifndef NK_VECTOR_STACK_SIZE 5397 #define NK_VECTOR_STACK_SIZE 16 5400 #ifndef NK_FLAGS_STACK_SIZE 5401 #define NK_FLAGS_STACK_SIZE 32 5404 #ifndef NK_COLOR_STACK_SIZE 5405 #define NK_COLOR_STACK_SIZE 32 5408 #define NK_CONFIGURATION_STACK_TYPE(prefix, name, type)\ 5409 struct nk_config_stack_##name##_element {\ 5410 prefix##_##type *address;\ 5411 prefix##_##type old_value;\ 5413 #define NK_CONFIG_STACK(type,size)\ 5414 struct nk_config_stack_##type {\ 5416 struct nk_config_stack_##type##_element elements[size];\ 5419 #define nk_float float 5449 #define NK_VALUE_PAGE_CAPACITY \ 5450 (((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint))) / 2) 5503 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 5504 struct nk_draw_list draw_list;
5506 #ifdef NK_INCLUDE_COMMAND_USERDATA 5533 #define NK_PI 3.141592654f 5534 #define NK_UTF_INVALID 0xFFFD 5535 #define NK_MAX_FLOAT_PRECISION 2 5537 #define NK_UNUSED(x) ((void)(x)) 5538 #define NK_SATURATE(x) (NK_MAX(0, NK_MIN(1.0f, x))) 5539 #define NK_LEN(a) (sizeof(a)/sizeof(a)[0]) 5540 #define NK_ABS(a) (((a) < 0) ? -(a) : (a)) 5541 #define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) < (b)) 5542 #define NK_INBOX(px, py, x, y, w, h)\ 5543 (NK_BETWEEN(px,x,x+w) && NK_BETWEEN(py,y,y+h)) 5544 #define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \ 5545 (!(((x1 > (x0 + w0)) || ((x1 + w1) < x0) || (y1 > (y0 + h0)) || (y1 + h1) < y0))) 5546 #define NK_CONTAINS(x, y, w, h, bx, by, bw, bh)\ 5547 (NK_INBOX(x,y, bx, by, bw, bh) && NK_INBOX(x+w,y+h, bx, by, bw, bh)) 5549 #define nk_vec2_sub(a, b) nk_vec2((a).x - (b).x, (a).y - (b).y) 5550 #define nk_vec2_add(a, b) nk_vec2((a).x + (b).x, (a).y + (b).y) 5551 #define nk_vec2_len_sqr(a) ((a).x*(a).x+(a).y*(a).y) 5552 #define nk_vec2_muls(a, t) nk_vec2((a).x * (t), (a).y * (t)) 5554 #define nk_ptr_add(t, p, i) ((t*)((void*)((nk_byte*)(p) + (i)))) 5555 #define nk_ptr_add_const(t, p, i) ((const t*)((const void*)((const nk_byte*)(p) + (i)))) 5556 #define nk_zero_struct(s) nk_zero(&s, sizeof(s)) 5562 #if defined(__PTRDIFF_TYPE__) 5563 # define NK_UINT_TO_PTR(x) ((void*)(__PTRDIFF_TYPE__)(x)) 5564 # define NK_PTR_TO_UINT(x) ((nk_size)(__PTRDIFF_TYPE__)(x)) 5565 #elif !defined(__GNUC__) 5566 # define NK_UINT_TO_PTR(x) ((void*)&((char*)0)[x]) 5567 # define NK_PTR_TO_UINT(x) ((nk_size)(((char*)x)-(char*)0)) 5568 #elif defined(NK_USE_FIXED_TYPES) 5569 # define NK_UINT_TO_PTR(x) ((void*)(uintptr_t)(x)) 5570 # define NK_PTR_TO_UINT(x) ((uintptr_t)(x)) 5572 # define NK_UINT_TO_PTR(x) ((void*)(x)) 5573 # define NK_PTR_TO_UINT(x) ((nk_size)(x)) 5576 #define NK_ALIGN_PTR(x, mask)\ 5577 (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x) + (mask-1)) & ~(mask-1)))) 5578 #define NK_ALIGN_PTR_BACK(x, mask)\ 5579 (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) 5581 #define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) 5582 #define NK_CONTAINER_OF(ptr,type,member)\ 5583 (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) 5590 template<
typename T>
struct nk_alignof;
5591 template<
typename T,
int size_diff>
struct nk_helper{
enum {value = size_diff};};
5592 template<
typename T>
struct nk_helper<
T,0>{
enum {value = nk_alignof<T>::value};};
5593 template<
typename T>
struct nk_alignof{
struct Big {
T x;
char c;};
enum {
5594 diff =
sizeof(Big) -
sizeof(
T), value = nk_helper<Big, diff>::value};};
5595 #define NK_ALIGNOF(t) (nk_alignof<t>::value) 5596 #elif defined(_MSC_VER) 5597 #define NK_ALIGNOF(t) (__alignof(t)) 5599 #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) 5605 #ifdef NK_IMPLEMENTATION 5607 #ifndef NK_INTERNAL_H 5608 #define NK_INTERNAL_H 5610 #ifndef NK_POOL_DEFAULT_CAPACITY 5611 #define NK_POOL_DEFAULT_CAPACITY 16 5614 #ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE 5615 #define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024) 5618 #ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE 5619 #define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024) 5623 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 5626 #ifdef NK_INCLUDE_STANDARD_IO 5629 #ifdef NK_INCLUDE_STANDARD_VARARGS 5634 #define NK_ASSERT(expr) assert(expr) 5638 #define NK_MEMSET nk_memset 5641 #define NK_MEMCPY nk_memcopy 5644 #define NK_SQRT nk_sqrt 5647 #define NK_SIN nk_sin 5650 #define NK_COS nk_cos 5653 #define NK_STRTOD nk_strtod 5656 #define NK_DTOA nk_dtoa 5659 #define NK_DEFAULT (-1) 5661 #ifndef NK_VSNPRINTF 5666 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||\ 5667 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ 5668 (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) ||\ 5669 (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) ||\ 5670 defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE) 5671 #define NK_VSNPRINTF(s,n,f,a) vsnprintf(s,n,f,a) 5673 #define NK_VSNPRINTF(s,n,f,a) vsprintf(s,f,a) 5677 #define NK_SCHAR_MIN (-127) 5678 #define NK_SCHAR_MAX 127 5679 #define NK_UCHAR_MIN 0 5680 #define NK_UCHAR_MAX 256 5681 #define NK_SSHORT_MIN (-32767) 5682 #define NK_SSHORT_MAX 32767 5683 #define NK_USHORT_MIN 0 5684 #define NK_USHORT_MAX 65535 5685 #define NK_SINT_MIN (-2147483647) 5686 #define NK_SINT_MAX 2147483647 5687 #define NK_UINT_MIN 0 5688 #define NK_UINT_MAX 4294967295u 5703 NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
5704 #define NK_FLOAT_PRECISION 0.00000000000001 5714 #define nk_widget_state_reset(s)\ 5715 if ((*(s)) & NK_WIDGET_STATE_MODIFIED)\ 5716 (*(s)) = NK_WIDGET_STATE_INACTIVE|NK_WIDGET_STATE_MODIFIED;\ 5717 else (*(s)) = NK_WIDGET_STATE_INACTIVE; 5720 NK_LIB float nk_inv_sqrt(
float n);
5721 NK_LIB float nk_sqrt(
float x);
5722 NK_LIB float nk_sin(
float x);
5723 NK_LIB float nk_cos(
float x);
5727 NK_LIB void nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
float x1,
float y1);
5728 NK_LIB double nk_pow(
double x,
int n);
5729 NK_LIB int nk_ifloord(
double x);
5730 NK_LIB int nk_ifloorf(
float x);
5731 NK_LIB int nk_iceilf(
float x);
5732 NK_LIB int nk_log10(
double n);
5735 enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
5736 NK_LIB int nk_is_lower(
int c);
5737 NK_LIB int nk_is_upper(
int c);
5738 NK_LIB int nk_to_upper(
int c);
5739 NK_LIB int nk_to_lower(
int c);
5740 NK_LIB void* nk_memcopy(
void *dst,
const void *src,
nk_size n);
5743 NK_LIB char *nk_itoa(
char *s,
long n);
5744 NK_LIB int nk_string_float_limit(
char *
string,
int prec);
5745 NK_LIB char *nk_dtoa(
char *s,
double n);
5746 NK_LIB int nk_text_clamp(
const struct nk_user_font *font,
const char *text,
int text_len,
float space,
int *glyphs,
float *text_width,
nk_rune *sep_list,
int sep_count);
5747 NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct
nk_user_font *font,
const char *begin,
int byte_len,
float row_height,
const char **remaining,
struct nk_vec2 *out_offset,
int *glyphs,
int op);
5748 #ifdef NK_INCLUDE_STANDARD_VARARGS 5749 NK_LIB int nk_strfmt(
char *buf,
int buf_size,
const char *fmt, va_list args);
5751 #ifdef NK_INCLUDE_STANDARD_IO 5756 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 5786 enum nk_window_insert_location {
5818 NK_LIB int nk_panel_has_header(
nk_flags flags,
const char *title);
5828 NK_LIB float nk_layout_row_calculate_usable_space(
const struct nk_style *style,
enum nk_panel_type type,
float total_space,
int columns);
5859 NK_LIB int nk_do_button_text_symbol(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
enum nk_symbol_type symbol,
const char *str,
int len,
nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
5861 NK_LIB int nk_do_button_text_image(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
struct nk_image img,
const char* str,
int len,
nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
5864 enum nk_toggle_type {
5879 NK_LIB float nk_slider_behavior(
nk_flags *state,
struct nk_rect *logical_cursor,
struct nk_rect *visual_cursor,
struct nk_input *in,
struct nk_rect bounds,
float slider_min,
float slider_max,
float slider_value,
float slider_step,
float slider_steps);
5884 NK_LIB float nk_scrollbar_behavior(
nk_flags *state,
struct nk_input *in,
int has_scrolling,
const struct nk_rect *scroll,
const struct nk_rect *cursor,
const struct nk_rect *empty0,
const struct nk_rect *empty1,
float scroll_offset,
float target,
float scroll_step,
enum nk_orientation o);
5886 NK_LIB float nk_do_scrollbarv(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
5887 NK_LIB float nk_do_scrollbarh(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
5890 NK_LIB void nk_draw_selectable(
struct nk_command_buffer *out,
nk_flags state,
const struct nk_style_selectable *style,
int active,
const struct nk_rect *bounds,
const struct nk_rect *icon,
const struct nk_image *img,
enum nk_symbol_type sym,
const char *
string,
int len,
nk_flags align,
const struct nk_user_font *font);
5892 NK_LIB int nk_do_selectable_image(
nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
const struct nk_image *img,
const struct nk_style_selectable *style,
const struct nk_input *in,
const struct nk_user_font *font);
5895 NK_LIB void nk_edit_draw_text(
struct nk_command_buffer *out,
const struct nk_style_edit *style,
float pos_x,
float pos_y,
float x_offset,
const char *text,
int byte_len,
float row_height,
const struct nk_user_font *font,
struct nk_color background,
struct nk_color foreground,
int is_selected);
5904 enum nk_property_status {
5905 NK_PROPERTY_DEFAULT,
5909 enum nk_property_filter {
5913 enum nk_property_kind {
5923 struct nk_property_variant {
5924 enum nk_property_kind kind;
5925 union nk_property value;
5926 union nk_property min_value;
5927 union nk_property max_value;
5928 union nk_property step;
5930 NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_value, int max_value, int step);
5931 NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step);
5932 NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step);
5934 NK_LIB void nk_drag_behavior(
nk_flags *state,
const struct nk_input *in,
struct nk_rect drag,
struct nk_property_variant *variant,
float inc_per_pixel);
5937 NK_LIB void nk_do_property(
nk_flags *ws,
struct nk_command_buffer *out,
struct nk_rect property,
const char *name,
struct nk_property_variant *variant,
float inc_per_pixel,
char *buffer,
int *len,
int *state,
int *cursor,
int *select_begin,
int *select_end,
const struct nk_style_property *style,
enum nk_property_filter filter,
struct nk_input *in,
const struct nk_user_font *font,
struct nk_text_edit *text_edit,
enum nk_button_behavior behavior);
5938 NK_LIB void nk_property(
struct nk_context *ctx,
const char *name,
struct nk_property_variant *variant,
float inc_per_pixel,
const enum nk_property_filter filter);
5979 nk_inv_sqrt(
float n)
5982 const float threehalfs = 1.5f;
5983 union {
nk_uint i;
float f;} conv = {0};
5986 conv.i = 0x5f375A84 - (conv.i >> 1);
5987 conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f));
5993 return x * nk_inv_sqrt(x);
5998 NK_STORAGE const float a0 = +1.91059300966915117e-31f;
5999 NK_STORAGE const float a1 = +1.00086760103908896f;
6000 NK_STORAGE const float a2 = -1.21276126894734565e-2f;
6001 NK_STORAGE const float a3 = -1.38078780785773762e-1f;
6002 NK_STORAGE const float a4 = -2.67353392911981221e-2f;
6003 NK_STORAGE const float a5 = +2.08026600266304389e-2f;
6004 NK_STORAGE const float a6 = -3.03996055049204407e-3f;
6005 NK_STORAGE const float a7 = +1.38235642404333740e-4f;
6006 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
6011 NK_STORAGE const float a0 = +1.00238601909309722f;
6012 NK_STORAGE const float a1 = -3.81919947353040024e-2f;
6013 NK_STORAGE const float a2 = -3.94382342128062756e-1f;
6014 NK_STORAGE const float a3 = -1.18134036025221444e-1f;
6015 NK_STORAGE const float a4 = +1.07123798512170878e-1f;
6016 NK_STORAGE const float a5 = -1.86637164165180873e-2f;
6017 NK_STORAGE const float a6 = +9.90140908664079833e-4f;
6018 NK_STORAGE const float a7 = -5.23022132118824778e-14f;
6019 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
6034 nk_pow(
double x,
int n)
6039 n = (plus) ? n : -n;
6046 return plus ? r : 1.0 / r;
6049 nk_ifloord(
double x)
6051 x = (double)((
int)x - ((x < 0.0) ? 1 : 0));
6057 x = (float)((
int)x - ((x < 0.0f) ? 1 : 0));
6065 return (x > i) ? i+1: i;
6068 float r = x - (float)t;
6069 return (r > 0.0f) ? t+1: t;
6079 neg = (n < 0) ? 1 : 0;
6080 ret = (neg) ? (
int)-n : (int)n;
6081 while ((ret / 10) > 0) {
6085 if (neg) exp = -exp;
6091 return nk_null_rect;
6114 return nk_rect(pos.x, pos.y, size.x, size.y);
6119 return nk_rect(r[0], r[1], r[2], r[3]);
6124 return nk_recti(r[0], r[1], r[2], r[3]);
6130 ret.
x = r.x; ret.y = r.y;
6137 ret.
x = r.w; ret.y = r.h;
6141 nk_shrink_rect(struct
nk_rect r, float amount)
6144 r.
w =
NK_MAX(r.w, 2 * amount);
6145 r.h =
NK_MAX(r.h, 2 * amount);
6146 res.x = r.x + amount;
6147 res.y = r.y + amount;
6148 res.w = r.w - 2 * amount;
6149 res.h = r.h - 2 * amount;
6156 r.h =
NK_MAX(r.h, 2 * pad.y);
6157 r.x += pad.x; r.y += pad.y;
6166 ret.
x =
x; ret.y =
y;
6188 nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
6203 float pad_x,
float pad_y,
enum nk_heading direction)
6205 float w_half, h_half;
6210 r.
w = r.
w - 2 * pad_x;
6211 r.
h = r.
h - 2 * pad_y;
6216 w_half = r.
w / 2.0f;
6217 h_half = r.
h / 2.0f;
6219 if (direction ==
NK_UP) {
6223 }
else if (direction ==
NK_RIGHT) {
6225 result[1] =
nk_vec2(r.
x + r.
w, r.
y + h_half);
6227 }
else if (direction ==
NK_DOWN) {
6230 result[2] =
nk_vec2(r.
x + w_half, r.
y + r.
h);
6247 NK_INTERN int nk_str_match_here(
const char *regexp,
const char *text);
6248 NK_INTERN int nk_str_match_star(
int c,
const char *regexp,
const char *text);
6249 NK_LIB int nk_is_lower(
int c) {
return (c >=
'a' && c <=
'z') || (c >= 0xE0 && c <= 0xFF);}
6250 NK_LIB int nk_is_upper(
int c){
return (c >=
'A' && c <=
'Z') || (c >= 0xC0 && c <= 0xDF);}
6251 NK_LIB int nk_to_upper(
int c) {
return (c >=
'a' && c <=
'z') ? (c - (
'a' -
'A')) : c;}
6252 NK_LIB int nk_to_lower(
int c) {
return (c >=
'A' && c <=
'Z') ? (c - (
'a' +
'A')) : c;}
6255 nk_memcopy(
void *dst0,
const void *src0,
nk_size length)
6258 char *dst = (
char*)dst0;
6259 const char *src = (
const char*)src0;
6260 if (length == 0 || dst == src)
6264 #define nk_wsize sizeof(nk_word) 6265 #define nk_wmask (nk_wsize-1) 6266 #define NK_TLOOP(s) if (t) NK_TLOOP1(s) 6267 #define NK_TLOOP1(s) do { s; } while (--t) 6271 if ((t | (
nk_ptr)dst) & nk_wmask) {
6272 if ((t ^ (
nk_ptr)dst) & nk_wmask || length < nk_wsize)
6275 t = nk_wsize - (t & nk_wmask);
6277 NK_TLOOP1(*dst++ = *src++);
6279 t = length / nk_wsize;
6280 NK_TLOOP(*(nk_word*)(
void*)dst = *(
const nk_word*)(
const void*)src;
6281 src += nk_wsize; dst += nk_wsize);
6282 t = length & nk_wmask;
6283 NK_TLOOP(*dst++ = *src++);
6288 if ((t | (
nk_ptr)dst) & nk_wmask) {
6289 if ((t ^ (
nk_ptr)dst) & nk_wmask || length <= nk_wsize)
6294 NK_TLOOP1(*--dst = *--src);
6296 t = length / nk_wsize;
6297 NK_TLOOP(src -= nk_wsize; dst -= nk_wsize;
6298 *(nk_word*)(
void*)dst = *(
const nk_word*)(
const void*)src);
6299 t = length & nk_wmask;
6300 NK_TLOOP(*--dst = *--src);
6311 nk_memset(
void *ptr,
int c0,
nk_size size)
6313 #define nk_word unsigned 6314 #define nk_wsize sizeof(nk_word) 6315 #define nk_wmask (nk_wsize - 1) 6322 if (
sizeof(
unsigned int) > 2)
6328 if (size < 3 * nk_wsize) {
6329 while (size--) *dst++ = (
nk_byte)c0;
6343 t = size / nk_wsize;
6345 *(nk_word*)((
void*)dst) = c;
6350 t = (size & nk_wmask);
6362 nk_zero(
void *ptr,
nk_size size)
6365 NK_MEMSET(ptr, 0, size);
6372 while (str && *str++ !=
'\0') siz++;
6376 nk_strtoi(
const char *str,
const char **endptr)
6379 const char *p = str;
6386 while (*p ==
' ') p++;
6391 while (*p && *p >=
'0' && *p <=
'9') {
6392 value = value * 10 + (int) (*p -
'0');
6400 nk_strtod(
const char *str,
const char **endptr)
6404 const char *p = str;
6412 while (*p ==
' ') p++;
6418 while (*p && *p !=
'.' && *p !=
'e') {
6419 value = value * 10.0 + (double) (*p -
'0');
6425 for(m = 0.1; *p && *p !=
'e'; p++ ) {
6426 value = value + (double) (*p -
'0') * m;
6436 }
else if (*p ==
'+') {
6441 for (pow = 0; *p; p++)
6442 pow = pow * 10 + (
int) (*p -
'0');
6444 for (m = 1.0, i = 0; i < pow; i++)
6451 number = value * neg;
6457 nk_strtof(
const char *str,
const char **endptr)
6460 double double_value;
6461 double_value = NK_STRTOD(str, endptr);
6462 float_value = (float)double_value;
6474 if (c1 <= 'Z' && c1 >=
'A') {
6478 if (c2 <= 'Z' && c2 >=
'A') {
6482 return ((d >= 0) << 1) - 1;
6488 nk_stricmpn(
const char *s1,
const char *s2,
int n)
6499 if (c1 <= 'Z' && c1 >=
'A') {
6503 if (c2 <= 'Z' && c2 >=
'A') {
6507 return ((d >= 0) << 1) - 1;
6513 nk_str_match_here(
const char *regexp,
const char *text)
6515 if (regexp[0] ==
'\0')
6517 if (regexp[1] ==
'*')
6518 return nk_str_match_star(regexp[0], regexp+2, text);
6519 if (regexp[0] ==
'$' && regexp[1] ==
'\0')
6520 return *text ==
'\0';
6521 if (*text!=
'\0' && (regexp[0]==
'.' || regexp[0]==*text))
6522 return nk_str_match_here(regexp+1, text+1);
6526 nk_str_match_star(
int c,
const char *regexp,
const char *text)
6529 if (nk_str_match_here(regexp, text))
6531 }
while (*text !=
'\0' && (*text++ == c || c ==
'.'));
6543 if (regexp[0] ==
'^')
6544 return nk_str_match_here(regexp+1, text);
6546 if (nk_str_match_here(regexp, text))
6548 }
while (*text++ !=
'\0');
6553 const char *pattern,
int *out_score)
6560 #define NK_ADJACENCY_BONUS 5 6562 #define NK_SEPARATOR_BONUS 10 6564 #define NK_CAMEL_BONUS 10 6566 #define NK_LEADING_LETTER_PENALTY (-3) 6568 #define NK_MAX_LEADING_LETTER_PENALTY (-9) 6570 #define NK_UNMATCHED_LETTER_PENALTY (-1) 6574 char const * pattern_iter = pattern;
6582 char const * best_letter = 0;
6583 int best_letter_score = 0;
6588 if (!str || !str_len || !pattern)
return 0;
6589 while (str_iter < str_len)
6591 const char pattern_letter = *pattern_iter;
6592 const char str_letter = str[str_iter];
6594 int next_match = *pattern_iter !=
'\0' &&
6595 nk_to_lower(pattern_letter) == nk_to_lower(str_letter);
6596 int rematch = best_letter && nk_to_upper(*best_letter) == nk_to_upper(str_letter);
6598 int advanced = next_match && best_letter;
6599 int pattern_repeat = best_letter && *pattern_iter !=
'\0';
6600 pattern_repeat = pattern_repeat &&
6601 nk_to_lower(*best_letter) == nk_to_lower(pattern_letter);
6603 if (advanced || pattern_repeat) {
6604 score += best_letter_score;
6606 best_letter_score = 0;
6609 if (next_match || rematch)
6613 if (pattern_iter == pattern) {
6614 int count = (int)(&str[str_iter] - str);
6615 int penalty = NK_LEADING_LETTER_PENALTY * count;
6616 if (penalty < NK_MAX_LEADING_LETTER_PENALTY)
6617 penalty = NK_MAX_LEADING_LETTER_PENALTY;
6624 new_score += NK_ADJACENCY_BONUS;
6628 new_score += NK_SEPARATOR_BONUS;
6631 if (prev_lower && nk_is_upper(str_letter))
6632 new_score += NK_CAMEL_BONUS;
6639 if (new_score >= best_letter_score) {
6641 if (best_letter != 0)
6642 score += NK_UNMATCHED_LETTER_PENALTY;
6644 best_letter = &str[str_iter];
6645 best_letter_score = new_score;
6649 score += NK_UNMATCHED_LETTER_PENALTY;
6654 prev_lower = nk_is_lower(str_letter) != 0;
6655 prev_separator = str_letter ==
'_' || str_letter ==
' ';
6662 score += best_letter_score;
6665 if (*pattern_iter !=
'\0')
6678 nk_string_float_limit(
char *
string,
int prec)
6688 if (dot == (prec+1)) {
6695 return (
int)(c - string);
6698 nk_strrev_ascii(
char *s)
6704 for (; i < end; ++i) {
6706 s[i] = s[len - 1 - i];
6711 nk_itoa(
char *s,
long n)
6724 s[i++] = (char)(
'0' + (n % 10));
6735 nk_dtoa(
char *s,
double n)
6738 int digit = 0, m = 0, m1 = 0;
6746 s[0] =
'0'; s[1] =
'\0';
6755 useExp = (m >= 14 || (neg && m >= 9) || m <= -9);
6756 if (neg) *(c++) =
'-';
6762 n = n / (double)nk_pow(10.0, m);
6771 while (n > NK_FLOAT_PRECISION || m >= 0) {
6772 double weight = nk_pow(10.0, m);
6774 double t = (double)n / weight;
6775 digit = nk_ifloord(t);
6776 n -= ((double)digit * weight);
6777 *(c++) = (
char)(
'0' + (char)digit);
6779 if (m == 0 && n > 0)
6796 *(c++) = (
char)(
'0' + (char)(m1 % 10));
6801 for (i = 0, j = m-1; i<j; i++, j--) {
6812 #ifdef NK_INCLUDE_STANDARD_VARARGS 6813 #ifndef NK_INCLUDE_STANDARD_IO 6815 nk_vsnprintf(
char *buf,
int buf_size,
const char *fmt, va_list args)
6820 NK_ARG_TYPE_DEFAULT,
6824 NK_ARG_FLAG_LEFT = 0x01,
6825 NK_ARG_FLAG_PLUS = 0x02,
6826 NK_ARG_FLAG_SPACE = 0x04,
6827 NK_ARG_FLAG_NUM = 0x10,
6828 NK_ARG_FLAG_ZERO = 0x20
6832 enum nk_arg_type arg_type = NK_ARG_TYPE_DEFAULT;
6833 int precision = NK_DEFAULT;
6834 int width = NK_DEFAULT;
6839 const char *iter = fmt;
6842 NK_ASSERT(buf_size);
6843 if (!buf || !buf_size || !fmt)
return 0;
6844 for (iter = fmt; *iter && len < buf_size; iter++) {
6846 while (*iter && (*iter !=
'%') && (len < buf_size))
6847 buf[len++] = *iter++;
6848 if (!(*iter) || len >= buf_size)
break;
6853 if (*iter ==
'-') flag |= NK_ARG_FLAG_LEFT;
6854 else if (*iter ==
'+') flag |= NK_ARG_FLAG_PLUS;
6855 else if (*iter ==
' ') flag |= NK_ARG_FLAG_SPACE;
6856 else if (*iter ==
'#') flag |= NK_ARG_FLAG_NUM;
6857 else if (*iter ==
'0') flag |= NK_ARG_FLAG_ZERO;
6864 if (*iter >=
'1' && *iter <=
'9') {
6870 }
else if (*iter ==
'*') {
6871 width = va_arg(args,
int);
6876 precision = NK_DEFAULT;
6880 precision = va_arg(args,
int);
6893 if (*(iter+1) ==
'h') {
6894 arg_type = NK_ARG_TYPE_CHAR;
6896 }
else arg_type = NK_ARG_TYPE_SHORT;
6898 }
else if (*iter ==
'l') {
6899 arg_type = NK_ARG_TYPE_LONG;
6901 }
else arg_type = NK_ARG_TYPE_DEFAULT;
6905 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
6906 NK_ASSERT(precision == NK_DEFAULT);
6907 NK_ASSERT(width == NK_DEFAULT);
6910 }
else if (*iter ==
's') {
6912 const char *str = va_arg(args,
const char*);
6913 NK_ASSERT(str != buf &&
"buffer and argument are not allowed to overlap!");
6914 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
6915 NK_ASSERT(precision == NK_DEFAULT);
6916 NK_ASSERT(width == NK_DEFAULT);
6917 if (str == buf)
return -1;
6918 while (str && *str && len < buf_size)
6919 buf[len++] = *str++;
6920 }
else if (*iter ==
'n') {
6922 signed int *n = va_arg(args,
int*);
6923 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
6924 NK_ASSERT(precision == NK_DEFAULT);
6925 NK_ASSERT(width == NK_DEFAULT);
6927 }
else if (*iter ==
'c' || *iter ==
'i' || *iter ==
'd') {
6930 const char *num_iter;
6931 int num_len, num_print, padding;
6932 int cur_precision =
NK_MAX(precision, 1);
6933 int cur_width =
NK_MAX(width, 0);
6936 if (arg_type == NK_ARG_TYPE_CHAR)
6937 value = (
signed char)va_arg(args,
int);
6938 else if (arg_type == NK_ARG_TYPE_SHORT)
6939 value = (
signed short)va_arg(args,
int);
6940 else if (arg_type == NK_ARG_TYPE_LONG)
6941 value = va_arg(args,
signed long);
6942 else if (*iter ==
'c')
6943 value = (
unsigned char)va_arg(args,
int);
6944 else value = va_arg(args,
signed int);
6947 nk_itoa(number_buffer, value);
6949 padding =
NK_MAX(cur_width -
NK_MAX(cur_precision, num_len), 0);
6950 if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE))
6951 padding =
NK_MAX(padding-1, 0);
6954 if (!(flag & NK_ARG_FLAG_LEFT)) {
6955 while (padding-- > 0 && (len < buf_size)) {
6956 if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT))
6958 else buf[len++] =
' ';
6963 if ((flag & NK_ARG_FLAG_PLUS) && value >= 0 && len < buf_size)
6965 else if ((flag & NK_ARG_FLAG_SPACE) && value >= 0 && len < buf_size)
6969 num_print =
NK_MAX(cur_precision, num_len);
6970 while (precision && (num_print > num_len) && (len < buf_size)) {
6976 num_iter = number_buffer;
6977 while (precision && *num_iter && len < buf_size)
6978 buf[len++] = *num_iter++;
6981 if (flag & NK_ARG_FLAG_LEFT) {
6982 while ((padding-- > 0) && (len < buf_size))
6985 }
else if (*iter ==
'o' || *iter ==
'x' || *iter ==
'X' || *iter ==
'u') {
6987 unsigned long value = 0;
6988 int num_len = 0, num_print, padding = 0;
6989 int cur_precision =
NK_MAX(precision, 1);
6990 int cur_width =
NK_MAX(width, 0);
6991 unsigned int base = (*iter ==
'o') ? 8: (*iter ==
'u')? 10: 16;
6994 const char *upper_output_format =
"0123456789ABCDEF";
6995 const char *lower_output_format =
"0123456789abcdef";
6996 const char *output_format = (*iter ==
'x') ?
6997 lower_output_format: upper_output_format;
7000 if (arg_type == NK_ARG_TYPE_CHAR)
7001 value = (
unsigned char)va_arg(args,
int);
7002 else if (arg_type == NK_ARG_TYPE_SHORT)
7003 value = (
unsigned short)va_arg(args,
int);
7004 else if (arg_type == NK_ARG_TYPE_LONG)
7005 value = va_arg(args,
unsigned long);
7006 else value = va_arg(args,
unsigned int);
7010 int digit = output_format[value % base];
7012 number_buffer[num_len++] = (char)digit;
7014 }
while (value > 0);
7016 num_print =
NK_MAX(cur_precision, num_len);
7017 padding =
NK_MAX(cur_width -
NK_MAX(cur_precision, num_len), 0);
7018 if (flag & NK_ARG_FLAG_NUM)
7019 padding =
NK_MAX(padding-1, 0);
7022 if (!(flag & NK_ARG_FLAG_LEFT)) {
7023 while ((padding-- > 0) && (len < buf_size)) {
7024 if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT))
7026 else buf[len++] =
' ';
7031 if (num_print && (flag & NK_ARG_FLAG_NUM)) {
7032 if ((*iter ==
'o') && (len < buf_size)) {
7034 }
else if ((*iter ==
'x') && ((len+1) < buf_size)) {
7037 }
else if ((*iter ==
'X') && ((len+1) < buf_size)) {
7042 while (precision && (num_print > num_len) && (len < buf_size)) {
7048 while (num_len > 0) {
7049 if (precision && (len < buf_size))
7050 buf[len++] = number_buffer[num_len-1];
7055 if (flag & NK_ARG_FLAG_LEFT) {
7056 while ((padding-- > 0) && (len < buf_size))
7059 }
else if (*iter ==
'f') {
7061 const char *num_iter;
7062 int cur_precision = (precision < 0) ? 6: precision;
7063 int prefix, cur_width =
NK_MAX(width, 0);
7064 double value = va_arg(args,
double);
7065 int num_len = 0, frac_len = 0, dot = 0;
7068 NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT);
7069 NK_DTOA(number_buffer, value);
7073 num_iter = number_buffer;
7074 while (*num_iter && *num_iter !=
'.')
7077 prefix = (*num_iter ==
'.')?(
int)(num_iter - number_buffer)+1:0;
7078 padding =
NK_MAX(cur_width - (prefix +
NK_MIN(cur_precision, num_len - prefix)) , 0);
7079 if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE))
7080 padding =
NK_MAX(padding-1, 0);
7083 if (!(flag & NK_ARG_FLAG_LEFT)) {
7084 while (padding-- > 0 && (len < buf_size)) {
7085 if (flag & NK_ARG_FLAG_ZERO)
7087 else buf[len++] =
' ';
7092 num_iter = number_buffer;
7093 if ((flag & NK_ARG_FLAG_PLUS) && (value >= 0) && (len < buf_size))
7095 else if ((flag & NK_ARG_FLAG_SPACE) && (value >= 0) && (len < buf_size))
7098 if (dot) frac_len++;
7100 buf[len++] = *num_iter;
7101 if (*num_iter ==
'.') dot = 1;
7102 if (frac_len >= cur_precision)
break;
7107 while (frac_len < cur_precision) {
7108 if (!dot && len < buf_size) {
7118 if (flag & NK_ARG_FLAG_LEFT) {
7119 while ((padding-- > 0) && (len < buf_size))
7124 NK_ASSERT(0 &&
"specifier is not supported!");
7128 buf[(len >= buf_size)?(buf_size-1):len] = 0;
7129 result = (len >= buf_size)?-1:len;
7134 nk_strfmt(
char *buf,
int buf_size,
const char *fmt, va_list args)
7138 NK_ASSERT(buf_size);
7139 if (!buf || !buf_size || !fmt)
return 0;
7140 #ifdef NK_INCLUDE_STANDARD_IO 7141 result = NK_VSNPRINTF(buf, (
nk_size)buf_size, fmt, args);
7142 result = (result >= buf_size) ? -1: result;
7143 buf[buf_size-1] = 0;
7145 result = nk_vsnprintf(buf, buf_size, fmt, args);
7154 #define NK_ROTL(x,r) ((x) << (r) | ((x) >> (32 - r))) 7157 const int nblocks = len/4;
7159 const nk_uint c1 = 0xcc9e2d51;
7160 const nk_uint c2 = 0x1b873593;
7168 conv.b = (data + nblocks*4);
7169 blocks = (
const nk_uint*)conv.i;
7170 for (i = -nblocks; i; ++i) {
7173 k1 = NK_ROTL(k1,15);
7177 h1 = NK_ROTL(h1,13);
7178 h1 = h1*5+0xe6546b64;
7182 tail = (
const nk_byte*)(data + nblocks*4);
7185 case 3: k1 ^= (
nk_uint)(tail[2] << 16);
7186 case 2: k1 ^= (
nk_uint)(tail[1] << 8u);
7187 case 1: k1 ^= tail[0];
7189 k1 = NK_ROTL(k1,15);
7208 #ifdef NK_INCLUDE_STANDARD_IO 7219 if (!path || !siz || !alloc)
7222 fd = fopen(path,
"rb");
7224 fseek(fd, 0, SEEK_END);
7231 fseek(fd, 0, SEEK_SET);
7238 *siz = (
nk_size)fread(buf, 1,*siz, fd);
7244 nk_text_clamp(
const struct nk_user_font *font,
const char *text,
7245 int text_len,
float space,
int *glyphs,
float *text_width,
7246 nk_rune *sep_list,
int sep_count)
7250 float last_width = 0;
7259 float sep_width = 0;
7260 sep_count =
NK_MAX(sep_count,0);
7263 while (glyph_len && (width < space) && (len < text_len)) {
7266 for (i = 0; i < sep_count; ++i) {
7267 if (unicode != sep_list[i])
continue;
7268 sep_width = last_width = width;
7273 if (i == sep_count){
7274 last_width = sep_width = width;
7278 glyph_len =
nk_utf_decode(&text[len], &unicode, text_len - len);
7281 if (len >= text_len) {
7283 *text_width = last_width;
7287 *text_width = sep_width;
7288 return (!sep_len) ? len: sep_len;
7292 nk_text_calculate_text_bounds(const struct
nk_user_font *font,
7293 const char *begin,
int byte_len,
float row_height,
const char **remaining,
7294 struct nk_vec2 *out_offset,
int *glyphs,
int op)
7296 float line_height = row_height;
7298 float line_width = 0.0f;
7304 if (!begin || byte_len <= 0 || !font)
7308 if (!glyph_len)
return text_size;
7309 glyph_width = font->width(font->userdata, font->height, begin, glyph_len);
7312 while ((text_len < byte_len) && glyph_len) {
7313 if (unicode ==
'\n') {
7314 text_size.
x =
NK_MAX(text_size.
x, line_width);
7315 text_size.
y += line_height;
7318 if (op == NK_STOP_ON_NEW_LINE)
7322 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7326 if (unicode ==
'\r') {
7329 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7333 *glyphs = *glyphs + 1;
7334 text_len += glyph_len;
7335 line_width += (float)glyph_width;
7336 glyph_len =
nk_utf_decode(begin + text_len, &unicode, byte_len-text_len);
7337 glyph_width = font->width(font->userdata, font->height, begin+text_len, glyph_len);
7341 if (text_size.
x < line_width)
7342 text_size.
x = line_width;
7344 *out_offset =
nk_vec2(line_width, text_size.
y + line_height);
7345 if (line_width > 0 || text_size.
y == 0.0f)
7346 text_size.
y += line_height;
7348 *remaining = begin+text_len;
7362 nk_parse_hex(
const char *p,
int length)
7366 while (len < length) {
7368 if (p[len] >=
'a' && p[len] <=
'f')
7369 i += ((p[len] -
'a') + 10);
7370 else if (p[len] >=
'A' && p[len] <=
'F')
7371 i += ((p[len] -
'A') + 10);
7372 else i += (p[len] -
'0');
7391 const char *c = rgb;
7393 col.
r = (
nk_byte)nk_parse_hex(c, 2);
7394 col.g = (
nk_byte)nk_parse_hex(c+2, 2);
7395 col.b = (
nk_byte)nk_parse_hex(c+4, 2);
7403 const char *c = rgb;
7405 col.
r = (
nk_byte)nk_parse_hex(c, 2);
7406 col.g = (
nk_byte)nk_parse_hex(c+2, 2);
7407 col.b = (
nk_byte)nk_parse_hex(c+4, 2);
7408 col.a = (
nk_byte)nk_parse_hex(c+6, 2);
7414 #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) 7415 output[0] = (char)NK_TO_HEX((col.
r & 0xF0) >> 4);
7416 output[1] = (char)NK_TO_HEX((col.
r & 0x0F));
7417 output[2] = (char)NK_TO_HEX((col.
g & 0xF0) >> 4);
7418 output[3] = (char)NK_TO_HEX((col.
g & 0x0F));
7419 output[4] = (char)NK_TO_HEX((col.
b & 0xF0) >> 4);
7420 output[5] = (char)NK_TO_HEX((col.
b & 0x0F));
7421 output[6] = (char)NK_TO_HEX((col.
a & 0xF0) >> 4);
7422 output[7] = (char)NK_TO_HEX((col.
a & 0x0F));
7429 #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) 7430 output[0] = (char)NK_TO_HEX((col.
r & 0xF0) >> 4);
7431 output[1] = (char)NK_TO_HEX((col.
r & 0x0F));
7432 output[2] = (char)NK_TO_HEX((col.
g & 0xF0) >> 4);
7433 output[3] = (char)NK_TO_HEX((col.
g & 0x0F));
7434 output[4] = (char)NK_TO_HEX((col.
b & 0xF0) >> 4);
7435 output[5] = (char)NK_TO_HEX((col.
b & 0x0F));
7442 return nk_rgba(c[0], c[1], c[2], c[3]);
7447 return nk_rgba(c[0], c[1], c[2], c[3]);
7462 return nk_rgb(c[0], c[1], c[2]);
7467 return nk_rgb(c[0], c[1], c[2]);
7473 ret.
r = (in & 0xFF);
7474 ret.g = ((in >> 8) & 0xFF);
7475 ret.b = ((in >> 16) & 0xFF);
7476 ret.a = (
nk_byte)((in >> 24) & 0xFF);
7492 return nk_rgba_f(c[0], c[1], c[2], c[3]);
7520 nk_hsv(int h, int s, int v)
7527 return nk_hsv(c[0], c[1], c[2]);
7532 return nk_hsv(c[0], c[1], c[2]);
7535 nk_hsv_f(float h, float s, float v)
7545 nk_hsva(int h, int s, int v, int
a)
7547 float hf = ((float)
NK_CLAMP(0, h, 255)) / 255.0f;
7548 float sf = ((float)
NK_CLAMP(0, s, 255)) / 255.0f;
7549 float vf = ((float)
NK_CLAMP(0, v, 255)) / 255.0f;
7550 float af = ((float)
NK_CLAMP(0,
a, 255)) / 255.0f;
7556 return nk_hsva(c[0], c[1], c[2], c[3]);
7561 return nk_hsva(c[0], c[1], c[2], c[3]);
7570 out.
r = v; out.
g = v; out.
b = v; out.
a =
a;
7573 h = h / (60.0f/360.0f);
7577 q = v * (1.0f - (s * f));
7578 t = v * (1.0f - s * (1.0f - f));
7581 case 0:
default: out.r = v; out.g = t; out.b = p;
break;
7582 case 1: out.r = q; out.g = v; out.b = p;
break;
7583 case 2: out.r = p; out.g = v; out.b = t;
break;
7584 case 3: out.r = p; out.g = q; out.b = v;
break;
7585 case 4: out.r = t; out.g = p; out.b = v;
break;
7586 case 5: out.r = v; out.g = p; out.b = q;
break;}
7596 nk_hsva_f(float h, float s, float v, float
a)
7604 return nk_hsva_f(c[0], c[1], c[2], c[3]);
7619 *
r = (float)in.
r * s;
7620 *
g = (
float)in.
g * s;
7621 *
b = (float)in.
b * s;
7622 *
a = (
float)in.
a * s;
7640 *
r = (double)in.
r * s;
7641 *
g = (
double)in.
g * s;
7642 *
b = (double)in.
b * s;
7643 *
a = (
double)in.
a * s;
7664 float *out_v,
float *out_a,
struct nk_colorf in)
7669 const float t = in.
g; in.
g = in.
b; in.
b = t;
7673 const float t = in.
r; in.
r = in.
g; in.
g = t;
7676 chroma = in.
r - ((in.
g < in.
b) ? in.
g: in.
b);
7677 *out_h =
NK_ABS(
K + (in.
g - in.
b)/(6.0f * chroma + 1e-20f));
7678 *out_s = chroma / (in.
r + 1e-20f);
7690 float *out_v,
float *out_a,
struct nk_color in)
7707 *out_h = (
nk_byte)(h * 255.0f);
7708 *out_s = (
nk_byte)(s * 255.0f);
7709 *out_v = (
nk_byte)(v * 255.0f);
7782 nk_utf_validate(
nk_rune *u,
int i)
7786 if (!
NK_BETWEEN(*u, nk_utfmin[i], nk_utfmax[i]) ||
7789 for (i = 1; *u > nk_utfmax[i]; ++i);
7793 nk_utf_decode_byte(
char c,
int *i)
7797 for(*i = 0; *i < (int)
NK_LEN(nk_utfmask); ++(*i)) {
7798 if (((
nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i])
7799 return (
nk_byte)(c & ~nk_utfmask[*i]);
7806 int i, j, len, type=0;
7812 if (!c || !u)
return 0;
7813 if (!clen)
return 0;
7816 udecoded = nk_utf_decode_byte(c[0], &len);
7820 for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
7821 udecoded = (udecoded << 6) | nk_utf_decode_byte(c[i], &type);
7828 nk_utf_validate(u, len);
7832 nk_utf_encode_byte(
nk_rune u,
int i)
7834 return (
char)((nk_utfbyte[i]) | ((
nk_byte)u & ~nk_utfmask[i]));
7840 len = nk_utf_validate(&u, 0);
7844 for (i = len - 1; i != 0; --i) {
7845 c[i] = nk_utf_encode_byte(u, 0);
7848 c[0] = nk_utf_encode_byte(u, len);
7862 if (!str || !len)
return 0;
7867 while (glyph_len && src_len < len) {
7869 src_len = src_len + glyph_len;
7870 glyph_len =
nk_utf_decode(text + src_len, &unicode, text_len - src_len);
7875 nk_utf_at(
const char *buffer,
int length,
int index,
7888 if (!buffer || !unicode || !len)
return 0;
7905 src_len = src_len + glyph_len;
7906 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
7908 if (i != index)
return 0;
7909 return buffer + src_len;
7921 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 7927 return malloc(size);
7936 nk_buffer_init_default(
struct nk_buffer *buffer)
7939 alloc.userdata.ptr = 0;
7940 alloc.alloc = nk_malloc;
7941 alloc.free = nk_mfree;
7952 NK_ASSERT(initial_size);
7953 if (!b || !a || !initial_size)
return;
7955 nk_zero(b,
sizeof(*b));
7959 b->
size = initial_size;
7969 if (!b || !m || !size)
return;
7971 nk_zero(b,
sizeof(*b));
7978 nk_buffer_align(
void *unaligned,
8021 if (!temp)
return 0;
8025 NK_MEMCPY(temp, b->
memory.
ptr, buffer_size);
8029 if (b->
size == buffer_size) {
8037 back_size = buffer_size - b->
size;
8038 dst =
nk_ptr_add(
void, temp, capacity - back_size);
8040 NK_MEMCPY(dst, src, back_size);
8041 b->
size = capacity - back_size;
8056 if (!b || !size)
return 0;
8063 memory = nk_buffer_align(unaligned, align, &alignment, type);
8088 memory = nk_buffer_align(unaligned, align, &alignment, type);
8092 else b->
size -= (size + alignment);
8101 void *mem = nk_buffer_alloc(b, type, size, align);
8103 NK_MEMCPY(mem, memory, size);
8109 if (!buffer)
return;
8119 if (!buffer)
return;
8161 if (!s || !b)
return;
8172 if (!buffer)
return 0;
8179 if (!buffer)
return 0;
8186 if (!buffer)
return 0;
8199 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 8201 nk_str_init_default(
struct nk_str *str)
8204 alloc.userdata.ptr = 0;
8205 alloc.alloc = nk_malloc;
8206 alloc.free = nk_mfree;
8230 if (!s || !str || !len)
return 0;
8233 NK_MEMCPY(mem, str, (
nk_size)len *
sizeof(
char));
8248 if (!str || !text || !len)
return 0;
8249 for (i = 0; i < len; ++i)
8262 if (!str || !text)
return 0;
8264 glyph_len = byte_len =
nk_utf_decode(text+byte_len, &unicode, 4);
8265 while (unicode !=
'\0' && glyph_len) {
8267 byte_len += glyph_len;
8281 if (!str || !text || !len)
return 0;
8282 for (i = 0; i < len; ++i) {
8284 if (!byte_len)
break;
8296 if (!str || !runes)
return 0;
8297 while (runes[i] !=
'\0') {
8315 NK_ASSERT(len >= 0);
8329 NK_ASSERT(((
int)pos + (
int)len + ((
int)copylen - 1)) >= 0);
8330 NK_ASSERT(((
int)pos + ((
int)copylen - 1)) >= 0);
8333 for (i = 0; i < copylen; ++i) *dst-- = *src--;
8335 NK_MEMCPY(mem, str, (
nk_size)len *
sizeof(
char));
8350 if (!str || !cstr || !len)
return 0;
8355 if (!begin)
return 0;
8377 if (!str || !text || !len)
return 0;
8378 for (i = 0; i < len; ++i)
8391 if (!str || !text)
return 0;
8393 glyph_len = byte_len =
nk_utf_decode(text+byte_len, &unicode, 4);
8394 while (unicode !=
'\0' && glyph_len) {
8396 byte_len += glyph_len;
8410 if (!str || !runes || !len)
return 0;
8411 for (i = 0; i < len; ++i) {
8413 if (!byte_len)
break;
8425 if (!str || !runes)
return 0;
8426 while (runes[i] !=
'\0') {
8437 NK_ASSERT(len >= 0);
8452 NK_ASSERT(len >= 0);
8453 if (!str || len < 0)
return;
8454 if (len >= str->
len) {
8459 index = str->
len - len;
8491 NK_ASSERT(s->
len >= pos + len);
8492 if (s->
len < pos + len)
8525 if (!str || !unicode || !len)
return 0;
8542 src_len = src_len + glyph_len;
8543 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
8545 if (i != pos)
return 0;
8546 return text + src_len;
8568 if (!str || !unicode || !len)
return 0;
8585 src_len = src_len + glyph_len;
8586 glyph_len =
nk_utf_decode(text + src_len, unicode, text_len - src_len);
8588 if (i != pos)
return 0;
8589 return text + src_len;
8657 if (!cb || !b)
return;
8672 b->
clip = nk_null_rect;
8673 #ifdef NK_INCLUDE_COMMAND_USERDATA 8695 unaligned = (
nk_byte*)cmd + size;
8698 #ifdef NK_ZERO_COMMAND_MEMORY 8699 NK_MEMSET(cmd, 0, size + alignment);
8704 #ifdef NK_INCLUDE_COMMAND_USERDATA 8725 cmd->
x = (short)r.
x;
8726 cmd->
y = (
short)r.
y;
8727 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
8728 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
8732 float x1,
float y1,
float line_thickness,
struct nk_color c)
8741 cmd->
begin.
x = (short)x0;
8742 cmd->
begin.
y = (short)y0;
8743 cmd->
end.
x = (short)x1;
8744 cmd->
end.
y = (short)y1;
8749 float ctrl0x,
float ctrl0y,
float ctrl1x,
float ctrl1y,
8760 cmd->
begin.
x = (short)ax;
8761 cmd->
begin.
y = (short)ay;
8762 cmd->
ctrl[0].
x = (short)ctrl0x;
8763 cmd->
ctrl[0].
y = (short)ctrl0y;
8764 cmd->
ctrl[1].
x = (short)ctrl1x;
8765 cmd->
ctrl[1].
y = (short)ctrl1y;
8766 cmd->
end.
x = (short)bx;
8767 cmd->
end.
y = (short)by;
8776 if (!b || c.
a == 0 || rect.
w == 0 || rect.
h == 0 ||
line_thickness <= 0)
return;
8780 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8787 cmd->
x = (short)rect.
x;
8788 cmd->
y = (
short)rect.
y;
8789 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8790 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8799 if (!b || c.
a == 0 || rect.
w == 0 || rect.
h == 0)
return;
8803 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8810 cmd->
x = (short)rect.
x;
8811 cmd->
y = (
short)rect.
y;
8812 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8813 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8823 if (!b || rect.
w == 0 || rect.
h == 0)
return;
8827 clip->
x, clip->
y, clip->
w, clip->
h))
return;
8833 cmd->
x = (short)rect.
x;
8834 cmd->
y = (
short)rect.
y;
8835 cmd->
w = (
unsigned short)
NK_MAX(0, rect.
w);
8836 cmd->
h = (
unsigned short)
NK_MAX(0, rect.
h);
8844 float line_thickness,
struct nk_color c)
8858 cmd->
x = (short)r.
x;
8859 cmd->
y = (
short)r.
y;
8860 cmd->
w = (
unsigned short)
NK_MAX(r.
w, 0);
8861 cmd->
h = (
unsigned short)
NK_MAX(r.
h, 0);
8869 if (!b || c.
a == 0 || r.
w == 0 || r.
h == 0)
return;
8879 cmd->
x = (short)r.
x;
8880 cmd->
y = (
short)r.
y;
8881 cmd->
w = (
unsigned short)
NK_MAX(r.
w, 0);
8882 cmd->
h = (
unsigned short)
NK_MAX(r.
h, 0);
8887 float a_min,
float a_max,
float line_thickness,
struct nk_color c)
8895 cmd->
cx = (short)
cx;
8896 cmd->
cy = (short)
cy;
8897 cmd->
r = (
unsigned short)radius;
8904 float a_min,
float a_max,
struct nk_color c)
8908 if (!b || c.
a == 0)
return;
8912 cmd->
cx = (short)
cx;
8913 cmd->
cy = (short)
cy;
8914 cmd->
r = (
unsigned short)radius;
8921 float y1,
float x2,
float y2,
float line_thickness,
struct nk_color c)
8926 if (
b->use_clipping) {
8928 if (!
NK_INBOX(x0, y0, clip->
x, clip->
y, clip->
w, clip->
h) &&
8929 !
NK_INBOX(x1, y1, clip->
x, clip->
y, clip->
w, clip->
h) &&
8938 cmd->
a.
x = (short)x0;
8939 cmd->
a.
y = (short)y0;
8940 cmd->
b.
x = (short)x1;
8941 cmd->
b.
y = (short)y1;
8942 cmd->
c.
x = (short)x2;
8943 cmd->
c.
y = (short)y2;
8948 float y1,
float x2,
float y2,
struct nk_color c)
8952 if (!
b ||
c.a == 0)
return;
8954 if (
b->use_clipping) {
8956 if (!
NK_INBOX(x0, y0, clip->
x, clip->
y, clip->
w, clip->
h) &&
8957 !
NK_INBOX(x1, y1, clip->
x, clip->
y, clip->
w, clip->
h) &&
8965 cmd->
a.
x = (short)x0;
8966 cmd->
a.
y = (short)y0;
8967 cmd->
b.
x = (short)x1;
8968 cmd->
b.
y = (short)y1;
8969 cmd->
c.
x = (short)x2;
8970 cmd->
c.
y = (short)y2;
8975 float line_thickness,
struct nk_color col)
9003 if (!b || col.
a == 0)
return;
9017 float line_thickness,
struct nk_color col)
9052 cmd->
x = (short)r.
x;
9053 cmd->
y = (
short)r.
y;
9054 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
9055 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
9075 cmd->
x = (short)r.
x;
9076 cmd->
y = (
short)r.
y;
9077 cmd->
w = (
unsigned short)
NK_MAX(0, r.
w);
9078 cmd->
h = (
unsigned short)
NK_MAX(0, r.
h);
9084 const char *
string,
int length,
const struct nk_user_font *font,
9087 float text_width = 0;
9092 if (!b || !
string || !
length || (bg.
a == 0 && fg.
a == 0))
return;
9101 if (text_width > r.
w){
9103 float txt_width = (float)text_width;
9104 length = nk_text_clamp(font,
string, length, r.
w, &glyphs, &txt_width, 0,0);
9107 if (!length)
return;
9111 cmd->
x = (short)r.
x;
9112 cmd->
y = (
short)r.
y;
9113 cmd->
w = (
unsigned short)r.
w;
9114 cmd->
h = (
unsigned short)r.
h;
9133 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 9135 nk_draw_list_init(
struct nk_draw_list *list)
9140 nk_zero(list,
sizeof(*list));
9141 for (i = 0; i <
NK_LEN(list->circle_vtx); ++i) {
9142 const float a = ((float)i / (
float)
NK_LEN(list->circle_vtx)) * 2 *
NK_PI;
9143 list->circle_vtx[i].x = (float)NK_COS(a);
9144 list->circle_vtx[i].y = (float)NK_SIN(a);
9148 nk_draw_list_setup(
struct nk_draw_list *canvas,
const struct nk_convert_config *config,
9155 NK_ASSERT(vertices);
9156 NK_ASSERT(elements);
9157 if (!canvas || !config || !cmds || !vertices || !elements)
9160 canvas->buffer = cmds;
9161 canvas->config = *config;
9162 canvas->elements = elements;
9163 canvas->vertices = vertices;
9164 canvas->line_AA = line_aa;
9165 canvas->shape_AA = shape_aa;
9166 canvas->clip_rect = nk_null_rect;
9168 canvas->cmd_offset = 0;
9169 canvas->element_count = 0;
9170 canvas->vertex_count = 0;
9171 canvas->cmd_offset = 0;
9172 canvas->cmd_count = 0;
9173 canvas->path_count = 0;
9175 NK_API const struct nk_draw_command*
9176 nk__draw_list_begin(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
9180 const struct nk_draw_command *cmd;
9183 if (!buffer || !buffer->
size || !canvas->cmd_count)
9187 offset = buffer->
memory.
size - canvas->cmd_offset;
9188 cmd =
nk_ptr_add(
const struct nk_draw_command, memory, offset);
9191 NK_API const struct nk_draw_command*
9192 nk__draw_list_end(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
9197 const struct nk_draw_command *end;
9201 if (!buffer || !canvas)
9206 offset = size - canvas->cmd_offset;
9207 end =
nk_ptr_add(
const struct nk_draw_command, memory, offset);
9208 end -= (canvas->cmd_count-1);
9211 NK_API const struct nk_draw_command*
9212 nk__draw_list_next(
const struct nk_draw_command *cmd,
9213 const struct nk_buffer *buffer,
const struct nk_draw_list *canvas)
9215 const struct nk_draw_command *end;
9218 if (!cmd || !buffer || !canvas)
9221 end = nk__draw_list_end(canvas, buffer);
9222 if (cmd <= end)
return 0;
9226 nk_draw_list_alloc_path(
struct nk_draw_list *list,
int count)
9233 point_size * (
nk_size)count, point_align);
9235 if (!points)
return 0;
9236 if (!list->path_offset) {
9238 list->path_offset = (
unsigned int)((
nk_byte*)points - (
nk_byte*)memory);
9240 list->path_count += (
unsigned int)count;
9244 nk_draw_list_path_last(struct nk_draw_list *list)
9248 NK_ASSERT(list->path_count);
9251 point += (list->path_count-1);
9255 nk_draw_list_push_command(
struct nk_draw_list *list,
struct nk_rect clip,
9260 struct nk_draw_command *cmd;
9263 cmd = (
struct nk_draw_command*)
9264 nk_buffer_alloc(list->buffer,
NK_BUFFER_BACK, cmd_size, cmd_align);
9267 if (!list->cmd_count) {
9274 cmd->elem_count = 0;
9275 cmd->clip_rect = clip;
9276 cmd->texture = texture;
9277 #ifdef NK_INCLUDE_COMMAND_USERDATA 9278 cmd->userdata = list->userdata;
9282 list->clip_rect = clip;
9286 nk_draw_list_command_last(
struct nk_draw_list *list)
9290 struct nk_draw_command *cmd;
9291 NK_ASSERT(list->cmd_count);
9295 cmd =
nk_ptr_add(
struct nk_draw_command, memory, size - list->cmd_offset);
9296 return (cmd - (list->cmd_count-1));
9299 nk_draw_list_add_clip(
struct nk_draw_list *list,
struct nk_rect rect)
9303 if (!list->cmd_count) {
9304 nk_draw_list_push_command(list, rect, list->config.null.texture);
9306 struct nk_draw_command *prev = nk_draw_list_command_last(list);
9307 if (prev->elem_count == 0)
9308 prev->clip_rect = rect;
9309 nk_draw_list_push_command(list, rect, prev->texture);
9313 nk_draw_list_push_image(
struct nk_draw_list *list,
nk_handle texture)
9317 if (!list->cmd_count) {
9318 nk_draw_list_push_command(list, nk_null_rect, texture);
9320 struct nk_draw_command *prev = nk_draw_list_command_last(list);
9321 if (prev->elem_count == 0) {
9322 prev->texture = texture;
9323 #ifdef NK_INCLUDE_COMMAND_USERDATA 9324 prev->userdata = list->userdata;
9326 }
else if (prev->texture.id != texture.
id 9327 #ifdef NK_INCLUDE_COMMAND_USERDATA
9328 || prev->userdata.id != list->userdata.id
9330 ) nk_draw_list_push_command(list, prev->clip_rect, texture);
9333 #ifdef NK_INCLUDE_COMMAND_USERDATA 9335 nk_draw_list_push_userdata(
struct nk_draw_list *list,
nk_handle userdata)
9337 list->userdata = userdata;
9341 nk_draw_list_alloc_vertices(
struct nk_draw_list *list,
nk_size count)
9345 if (!list)
return 0;
9347 list->config.vertex_size*count, list->config.vertex_alignment);
9349 list->vertex_count += (
unsigned int)count;
9353 nk_draw_list_alloc_elements(
struct nk_draw_list *list,
nk_size count)
9356 struct nk_draw_command *cmd;
9360 if (!list)
return 0;
9362 ids = (nk_draw_index*)
9363 nk_buffer_alloc(list->elements,
NK_BUFFER_FRONT, elem_size*count, elem_align);
9365 cmd = nk_draw_list_command_last(list);
9366 list->element_count += (
unsigned int)count;
9367 cmd->elem_count += (
unsigned int)count;
9371 nk_draw_vertex_layout_element_is_end_of_layout(
9372 const struct nk_draw_vertex_layout_element *element)
9374 return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT ||
9375 element->format == NK_FORMAT_COUNT);
9378 nk_draw_vertex_color(
void *attr,
const float *vals,
9379 enum nk_draw_vertex_layout_format format)
9383 NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN);
9384 NK_ASSERT(format <= NK_FORMAT_COLOR_END);
9385 if (format < NK_FORMAT_COLOR_BEGIN || format > NK_FORMAT_COLOR_END)
return;
9393 default: NK_ASSERT(0 &&
"Invalid vertex layout color format");
break;
9394 case NK_FORMAT_R8G8B8A8:
9395 case NK_FORMAT_R8G8B8: {
9397 NK_MEMCPY(attr, &col.
r,
sizeof(col));
9399 case NK_FORMAT_B8G8R8A8: {
9402 NK_MEMCPY(attr, &bgra,
sizeof(bgra));
9404 case NK_FORMAT_R16G15B16: {
9406 col[0] = (
nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
9407 col[1] = (
nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
9408 col[2] = (
nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
9409 NK_MEMCPY(attr, col,
sizeof(col));
9411 case NK_FORMAT_R16G15B16A16: {
9413 col[0] = (
nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
9414 col[1] = (
nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
9415 col[2] = (
nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
9416 col[3] = (
nk_ushort)(val[3]*(
float)NK_USHORT_MAX);
9417 NK_MEMCPY(attr, col,
sizeof(col));
9419 case NK_FORMAT_R32G32B32: {
9421 col[0] = (
nk_uint)(val[0]*(
float)NK_UINT_MAX);
9422 col[1] = (
nk_uint)(val[1]*(
float)NK_UINT_MAX);
9423 col[2] = (
nk_uint)(val[2]*(
float)NK_UINT_MAX);
9424 NK_MEMCPY(attr, col,
sizeof(col));
9426 case NK_FORMAT_R32G32B32A32: {
9428 col[0] = (
nk_uint)(val[0]*(
float)NK_UINT_MAX);
9429 col[1] = (
nk_uint)(val[1]*(
float)NK_UINT_MAX);
9430 col[2] = (
nk_uint)(val[2]*(
float)NK_UINT_MAX);
9431 col[3] = (
nk_uint)(val[3]*(
float)NK_UINT_MAX);
9432 NK_MEMCPY(attr, col,
sizeof(col));
9434 case NK_FORMAT_R32G32B32A32_FLOAT:
9435 NK_MEMCPY(attr, val,
sizeof(
float)*4);
9437 case NK_FORMAT_R32G32B32A32_DOUBLE: {
9439 col[0] = (double)val[0];
9440 col[1] = (double)val[1];
9441 col[2] = (double)val[2];
9442 col[3] = (double)val[3];
9443 NK_MEMCPY(attr, col,
sizeof(col));
9445 case NK_FORMAT_RGB32:
9446 case NK_FORMAT_RGBA32: {
9449 NK_MEMCPY(attr, &color,
sizeof(color));
9453 nk_draw_vertex_element(
void *dst,
const float *values,
int value_count,
9454 enum nk_draw_vertex_layout_format format)
9457 void *attribute = dst;
9459 NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN);
9460 if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END)
return;
9461 for (value_index = 0; value_index < value_count; ++value_index) {
9463 default: NK_ASSERT(0 &&
"invalid vertex layout format");
break;
9464 case NK_FORMAT_SCHAR: {
9465 char value = (char)
NK_CLAMP((
float)NK_SCHAR_MIN, values[value_index], (float)NK_SCHAR_MAX);
9466 NK_MEMCPY(attribute, &value,
sizeof(value));
9467 attribute = (
void*)((
char*)attribute +
sizeof(char));
9469 case NK_FORMAT_SSHORT: {
9471 NK_MEMCPY(attribute, &value,
sizeof(value));
9472 attribute = (
void*)((
char*)attribute +
sizeof(value));
9474 case NK_FORMAT_SINT: {
9476 NK_MEMCPY(attribute, &value,
sizeof(value));
9477 attribute = (
void*)((
char*)attribute +
sizeof(
nk_int));
9479 case NK_FORMAT_UCHAR: {
9480 unsigned char value = (
unsigned char)
NK_CLAMP((
float)NK_UCHAR_MIN, values[value_index], (float)NK_UCHAR_MAX);
9481 NK_MEMCPY(attribute, &value,
sizeof(value));
9482 attribute = (
void*)((
char*)attribute +
sizeof(
unsigned char));
9484 case NK_FORMAT_USHORT: {
9486 NK_MEMCPY(attribute, &value,
sizeof(value));
9487 attribute = (
void*)((
char*)attribute +
sizeof(value));
9489 case NK_FORMAT_UINT: {
9491 NK_MEMCPY(attribute, &value,
sizeof(value));
9492 attribute = (
void*)((
char*)attribute +
sizeof(
nk_uint));
9494 case NK_FORMAT_FLOAT:
9495 NK_MEMCPY(attribute, &values[value_index],
sizeof(values[value_index]));
9496 attribute = (
void*)((
char*)attribute +
sizeof(float));
9498 case NK_FORMAT_DOUBLE: {
9499 double value = (double)values[value_index];
9500 NK_MEMCPY(attribute, &value,
sizeof(value));
9501 attribute = (
void*)((
char*)attribute +
sizeof(double));
9510 void *result = (
void*)((
char*)dst + config->
vertex_size);
9511 const struct nk_draw_vertex_layout_element *elem_iter = config->
vertex_layout;
9512 while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) {
9513 void *address = (
void*)((
char*)dst + elem_iter->offset);
9514 switch (elem_iter->attribute) {
9515 case NK_VERTEX_ATTRIBUTE_COUNT:
9516 default: NK_ASSERT(0 &&
"wrong element attribute");
break;
9517 case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.
x, 2, elem_iter->format);
break;
9518 case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.
x, 2, elem_iter->format);
break;
9519 case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.
r, elem_iter->format);
break;
9526 nk_draw_list_stroke_poly_line(
struct nk_draw_list *list,
const struct nk_vec2 *points,
9527 const unsigned int points_count,
struct nk_color color,
enum nk_draw_list_stroke closed,
9535 if (!list || points_count < 2)
return;
9537 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9538 count = points_count;
9539 if (!closed) count = points_count-1;
9540 thick_line = thickness > 1.0f;
9542 #ifdef NK_INCLUDE_COMMAND_USERDATA 9543 nk_draw_list_push_userdata(list, list->userdata);
9546 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9553 const float AA_SIZE = 1.0f;
9560 nk_size index = list->vertex_count;
9562 const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12);
9563 const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3);
9565 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9566 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9569 struct nk_vec2 *normals, *temp;
9570 if (!vtx || !ids)
return;
9575 size = pnt_size * ((thick_line) ? 5 : 3) * points_count;
9577 if (!normals)
return;
9578 temp = normals + points_count;
9581 vtx = (
void*)((
nk_byte*)list->vertices->memory.ptr + vertex_offset);
9584 for (i1 = 0; i1 < count; ++i1) {
9585 const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
9592 len = nk_inv_sqrt(len);
9596 normals[i1].
x = diff.
y;
9597 normals[i1].
y = -diff.
x;
9601 normals[points_count-1] = normals[points_count-2];
9610 temp[(points_count-1) * 2 + 0] =
nk_vec2_add(points[points_count-1], d);
9611 temp[(points_count-1) * 2 + 1] =
nk_vec2_sub(points[points_count-1], d);
9616 for (i1 = 0; i1 < count; i1++) {
9619 nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
9620 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3);
9624 dmr2 = dm.x * dm.x + dm.y* dm.y;
9625 if (dmr2 > 0.000001f) {
9626 float scale = 1.0f/dmr2;
9627 scale =
NK_MIN(100.0f, scale);
9635 ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0);
9636 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
9637 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0);
9638 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
9639 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
9640 ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1);
9646 for (i = 0; i < points_count; ++i) {
9647 const struct nk_vec2 uv = list->config.null.uv;
9648 vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
9649 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
9650 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
9654 const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f;
9664 d1 =
nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE);
9665 d2 =
nk_vec2_muls(normals[points_count-1], half_inner_thickness);
9667 temp[(points_count-1)*4+0] =
nk_vec2_add(points[points_count-1], d1);
9668 temp[(points_count-1)*4+1] =
nk_vec2_add(points[points_count-1], d2);
9669 temp[(points_count-1)*4+2] =
nk_vec2_sub(points[points_count-1], d2);
9670 temp[(points_count-1)*4+3] =
nk_vec2_sub(points[points_count-1], d1);
9675 for (i1 = 0; i1 < count; ++i1) {
9677 const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1);
9678 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4);
9682 float dmr2 = dm.
x * dm.
x + dm.
y* dm.
y;
9683 if (dmr2 > 0.000001f) {
9684 float scale = 1.0f/dmr2;
9685 scale =
NK_MIN(100.0f, scale);
9689 dm_out =
nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE));
9697 ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1);
9698 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
9699 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1);
9700 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
9701 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
9702 ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1);
9703 ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2);
9704 ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3);
9705 ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2);
9711 for (i = 0; i < points_count; ++i) {
9712 const struct nk_vec2 uv = list->config.null.uv;
9713 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
9714 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
9715 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
9716 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans);
9724 nk_size idx = list->vertex_count;
9725 const nk_size idx_count = count * 6;
9726 const nk_size vtx_count = count * 4;
9727 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9728 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9729 if (!vtx || !ids)
return;
9731 for (i1 = 0; i1 < count; ++i1) {
9733 const struct nk_vec2 uv = list->config.null.uv;
9734 const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
9735 const struct nk_vec2 p1 = points[i1];
9736 const struct nk_vec2 p2 = points[i2];
9743 len = nk_inv_sqrt(len);
9748 dx = diff.
x * (thickness * 0.5f);
9749 dy = diff.
y * (thickness * 0.5f);
9751 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.
x + dy, p1.
y - dx), uv, col);
9752 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.
x + dy, p2.
y - dx), uv, col);
9753 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.
x - dy, p2.
y + dx), uv, col);
9754 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.
x - dy, p1.
y + dx), uv, col);
9756 ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1);
9757 ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0);
9758 ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3);
9766 nk_draw_list_fill_poly_convex(
struct nk_draw_list *list,
9767 const struct nk_vec2 *points,
const unsigned int points_count,
9776 if (!list || points_count < 3)
return;
9778 #ifdef NK_INCLUDE_COMMAND_USERDATA 9779 nk_draw_list_push_userdata(list, list->userdata);
9782 color.
a = (
nk_byte)((
float)color.
a * list->config.global_alpha);
9792 const float AA_SIZE = 1.0f;
9794 nk_size index = list->vertex_count;
9796 const nk_size idx_count = (points_count-2)*3 + points_count*6;
9797 const nk_size vtx_count = (points_count*2);
9799 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9800 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9804 unsigned int vtx_inner_idx = (
unsigned int)(index + 0);
9805 unsigned int vtx_outer_idx = (
unsigned int)(index + 1);
9806 if (!vtx || !ids)
return;
9811 size = pnt_size * points_count;
9813 if (!normals)
return;
9814 vtx = (
void*)((
nk_byte*)list->vertices->memory.ptr + vertex_offset);
9817 for (i = 2; i < points_count; i++) {
9818 ids[0] = (nk_draw_index)(vtx_inner_idx);
9819 ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1));
9820 ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1));
9825 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
9826 struct nk_vec2 p0 = points[i0];
9827 struct nk_vec2 p1 = points[i1];
9833 len = nk_inv_sqrt(len);
9837 normals[i0].
x = diff.
y;
9838 normals[i0].
y = -diff.
x;
9842 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
9843 const struct nk_vec2 uv = list->config.null.uv;
9844 struct nk_vec2 n0 = normals[i0];
9845 struct nk_vec2 n1 = normals[i1];
9847 float dmr2 = dm.
x*dm.
x + dm.
y*dm.
y;
9848 if (dmr2 > 0.000001f) {
9849 float scale = 1.0f / dmr2;
9850 scale =
NK_MIN(scale, 100.0f);
9856 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2_sub(points[i1], dm), uv, col);
9857 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2_add(points[i1], dm), uv, col_trans);
9860 ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
9861 ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1));
9862 ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
9863 ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
9864 ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1));
9865 ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
9872 nk_size index = list->vertex_count;
9873 const nk_size idx_count = (points_count-2)*3;
9874 const nk_size vtx_count = points_count;
9875 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
9876 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
9878 if (!vtx || !ids)
return;
9879 for (i = 0; i < vtx_count; ++i)
9880 vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col);
9881 for (i = 2; i < points_count; ++i) {
9882 ids[0] = (nk_draw_index)index;
9883 ids[1] = (nk_draw_index)(index+ i - 1);
9884 ids[2] = (nk_draw_index)(index+i);
9890 nk_draw_list_path_clear(
struct nk_draw_list *list)
9895 list->path_count = 0;
9896 list->path_offset = 0;
9899 nk_draw_list_path_line_to(
struct nk_draw_list *list,
struct nk_vec2 pos)
9902 struct nk_draw_command *cmd = 0;
9905 if (!list->cmd_count)
9906 nk_draw_list_add_clip(list, nk_null_rect);
9908 cmd = nk_draw_list_command_last(list);
9909 if (cmd && cmd->texture.ptr != list->config.null.texture.ptr)
9910 nk_draw_list_push_image(list, list->config.null.texture);
9912 points = nk_draw_list_alloc_path(list, 1);
9913 if (!points)
return;
9917 nk_draw_list_path_arc_to_fast(
struct nk_draw_list *list,
struct nk_vec2 center,
9918 float radius,
int a_min,
int a_max)
9923 if (a_min <= a_max) {
9924 for (a = a_min; a <= a_max; a++) {
9926 const float x = center.
x + c.
x * radius;
9927 const float y = center.
y + c.
y * radius;
9928 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
9933 nk_draw_list_path_arc_to(
struct nk_draw_list *list,
struct nk_vec2 center,
9934 float radius,
float a_min,
float a_max,
unsigned int segments)
9939 if (radius == 0.0f)
return;
9959 {
const float d_angle = (a_max - a_min) / (
float)segments;
9960 const float sin_d = (float)NK_SIN(d_angle);
9961 const float cos_d = (float)NK_COS(d_angle);
9963 float cx = (float)NK_COS(a_min) * radius;
9964 float cy = (float)NK_SIN(a_min) * radius;
9965 for(i = 0; i <= segments; ++i) {
9966 float new_cx, new_cy;
9967 const float x = center.
x + cx;
9968 const float y = center.
y + cy;
9969 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
9971 new_cx = cx * cos_d - cy * sin_d;
9972 new_cy = cy * cos_d + cx * sin_d;
9978 nk_draw_list_path_rect_to(
struct nk_draw_list *list,
struct nk_vec2 a,
9979 struct nk_vec2 b,
float rounding)
9985 r =
NK_MIN(r, ((b.
x-a.
x) < 0) ? -(b.
x-a.
x): (b.
x-a.
x));
9986 r =
NK_MIN(r, ((b.
y-a.
y) < 0) ? -(b.
y-a.
y): (b.
y-a.
y));
9989 nk_draw_list_path_line_to(list, a);
9990 nk_draw_list_path_line_to(list,
nk_vec2(b.
x,a.
y));
9991 nk_draw_list_path_line_to(list, b);
9992 nk_draw_list_path_line_to(list,
nk_vec2(a.
x,b.
y));
9994 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.
x + r, a.
y + r), r, 6, 9);
9995 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.
x - r, a.
y + r), r, 9, 12);
9996 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.
x - r, b.
y - r), r, 0, 3);
9997 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.
x + r, b.
y - r), r, 3, 6);
10001 nk_draw_list_path_curve_to(
struct nk_draw_list *list,
struct nk_vec2 p2,
10002 struct nk_vec2 p3,
struct nk_vec2 p4,
unsigned int num_segments)
10005 unsigned int i_step;
10009 NK_ASSERT(list->path_count);
10010 if (!list || !list->path_count)
return;
10011 num_segments =
NK_MAX(num_segments, 1);
10013 p1 = nk_draw_list_path_last(list);
10014 t_step = 1.0f/(float)num_segments;
10015 for (i_step = 1; i_step <= num_segments; ++i_step) {
10016 float t = t_step * (float)i_step;
10017 float u = 1.0f - t;
10019 float w2 = 3*u*u*t;
10020 float w3 = 3*u*t*t;
10021 float w4 = t * t *t;
10022 float x = w1 * p1.
x + w2 * p2.
x + w3 * p3.
x + w4 * p4.
x;
10023 float y = w1 * p1.
y + w2 * p2.
y + w3 * p3.
y + w4 * p4.
y;
10024 nk_draw_list_path_line_to(list,
nk_vec2(
x,
y));
10028 nk_draw_list_path_fill(
struct nk_draw_list *list,
struct nk_color color)
10034 nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA);
10035 nk_draw_list_path_clear(list);
10038 nk_draw_list_path_stroke(
struct nk_draw_list *list,
struct nk_color color,
10039 enum nk_draw_list_stroke closed,
float thickness)
10045 nk_draw_list_stroke_poly_line(list, points, list->path_count, color,
10046 closed, thickness, list->config.line_AA);
10047 nk_draw_list_path_clear(list);
10050 nk_draw_list_stroke_line(
struct nk_draw_list *list,
struct nk_vec2 a,
10054 if (!list || !col.
a)
return;
10056 nk_draw_list_path_line_to(list, a);
10057 nk_draw_list_path_line_to(list, b);
10062 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
10065 nk_draw_list_fill_rect(
struct nk_draw_list *list,
struct nk_rect rect,
10066 struct nk_color col,
float rounding)
10069 if (!list || !col.
a)
return;
10072 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x, rect.
y),
10073 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10075 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x-0.5f, rect.
y-0.5f),
10076 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10077 } nk_draw_list_path_fill(list, col);
10080 nk_draw_list_stroke_rect(
struct nk_draw_list *list,
struct nk_rect rect,
10081 struct nk_color col,
float rounding,
float thickness)
10084 if (!list || !col.
a)
return;
10086 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x, rect.
y),
10087 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10089 nk_draw_list_path_rect_to(list,
nk_vec2(rect.
x-0.5f, rect.
y-0.5f),
10090 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), rounding);
10091 } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10094 nk_draw_list_fill_rect_multi_color(
struct nk_draw_list *list,
struct nk_rect rect,
10100 struct nk_colorf col_right, col_bottom;
10101 nk_draw_index *idx;
10102 nk_draw_index index;
10112 nk_draw_list_push_image(list, list->config.null.texture);
10113 index = (nk_draw_index)list->vertex_count;
10114 vtx = nk_draw_list_alloc_vertices(list, 4);
10115 idx = nk_draw_list_alloc_elements(list, 6);
10116 if (!vtx || !idx)
return;
10118 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
10119 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
10120 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
10122 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x, rect.
y), list->config.null.uv, col_left);
10123 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x + rect.
w, rect.
y), list->config.null.uv, col_top);
10124 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), list->config.null.uv, col_right);
10125 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.
x, rect.
y + rect.
h), list->config.null.uv, col_bottom);
10128 nk_draw_list_fill_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
10132 if (!list || !col.
a)
return;
10133 nk_draw_list_path_line_to(list,
a);
10134 nk_draw_list_path_line_to(list,
b);
10135 nk_draw_list_path_line_to(list, c);
10136 nk_draw_list_path_fill(list, col);
10139 nk_draw_list_stroke_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
10143 if (!list || !col.
a)
return;
10144 nk_draw_list_path_line_to(list,
a);
10145 nk_draw_list_path_line_to(list,
b);
10146 nk_draw_list_path_line_to(list, c);
10147 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10150 nk_draw_list_fill_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
10151 float radius,
struct nk_color col,
unsigned int segs)
10155 if (!list || !col.
a)
return;
10156 a_max =
NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
10157 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
10158 nk_draw_list_path_fill(list, col);
10161 nk_draw_list_stroke_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
10162 float radius,
struct nk_color col,
unsigned int segs,
float thickness)
10166 if (!list || !col.
a)
return;
10167 a_max =
NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
10168 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
10169 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
10172 nk_draw_list_stroke_curve(
struct nk_draw_list *list,
struct nk_vec2 p0,
10174 struct nk_color col,
unsigned int segments,
float thickness)
10177 if (!list || !col.
a)
return;
10178 nk_draw_list_path_line_to(list, p0);
10179 nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments);
10180 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
10183 nk_draw_list_push_rect_uv(
struct nk_draw_list *list,
struct nk_vec2 a,
10194 nk_draw_index *idx;
10195 nk_draw_index index;
10205 index = (nk_draw_index)list->vertex_count;
10206 vtx = nk_draw_list_alloc_vertices(list, 4);
10207 idx = nk_draw_list_alloc_elements(list, 6);
10208 if (!vtx || !idx)
return;
10210 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
10211 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
10212 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
10214 vtx = nk_draw_vertex(vtx, &list->config,
a, uva, col);
10215 vtx = nk_draw_vertex(vtx, &list->config,
b, uvb, col);
10216 vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col);
10217 vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col);
10220 nk_draw_list_add_image(
struct nk_draw_list *list,
struct nk_image texture,
10226 nk_draw_list_push_image(list, texture.
handle);
10230 uv[0].
x = (float)texture.
region[0]/(
float)texture.
w;
10231 uv[0].
y = (float)texture.
region[1]/(
float)texture.
h;
10232 uv[1].
x = (float)(texture.
region[0] + texture.
region[2])/(float)texture.
w;
10233 uv[1].y = (
float)(texture.
region[1] + texture.
region[3])/(
float)texture.
h;
10234 nk_draw_list_push_rect_uv(list,
nk_vec2(rect.
x, rect.
y),
10235 nk_vec2(rect.
x + rect.
w, rect.
y + rect.
h), uv[0], uv[1], color);
10236 }
else nk_draw_list_push_rect_uv(list,
nk_vec2(rect.
x, rect.
y),
10241 nk_draw_list_add_text(
struct nk_draw_list *list,
const struct nk_user_font *font,
10242 struct nk_rect rect,
const char *text,
int len,
float font_height,
10250 int next_glyph_len = 0;
10251 struct nk_user_font_glyph g;
10254 if (!list || !len || !text)
return;
10256 list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h))
return;
10258 nk_draw_list_push_image(list, font->texture);
10261 if (!glyph_len)
return;
10264 fg.
a = (
nk_byte)((
float)fg.
a * list->config.global_alpha);
10265 while (text_len < len && glyph_len) {
10266 float gx, gy, gh, gw;
10267 float char_width = 0;
10271 next_glyph_len =
nk_utf_decode(text + text_len + glyph_len, &next, (
int)len - text_len);
10272 font->query(font->
userdata, font_height, &g, unicode,
10276 gx = x + g.offset.x;
10277 gy = rect.
y + g.offset.y;
10278 gw = g.width; gh = g.height;
10279 char_width = g.xadvance;
10280 nk_draw_list_push_rect_uv(list,
nk_vec2(gx,gy),
nk_vec2(gx + gw, gy+ gh),
10281 g.uv[0], g.uv[1], fg);
10284 text_len += glyph_len;
10286 glyph_len = next_glyph_len;
10299 NK_ASSERT(vertices);
10300 NK_ASSERT(elements);
10304 if (!ctx || !cmds || !vertices || !elements || !config || !config->
vertex_layout)
10307 nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements,
10311 #ifdef NK_INCLUDE_COMMAND_USERDATA 10312 ctx->draw_list.userdata = cmd->userdata;
10314 switch (cmd->
type) {
10318 nk_draw_list_add_clip(&ctx->draw_list,
nk_rect(s->
x, s->
y, s->
w, s->
h));
10334 nk_draw_list_stroke_rect(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10339 nk_draw_list_fill_rect(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10344 nk_draw_list_fill_rect_multi_color(&ctx->draw_list,
nk_rect(r->
x, r->
y, r->
w, r->
h),
10349 nk_draw_list_stroke_circle(&ctx->draw_list,
nk_vec2((
float)c->
x + (
float)c->
w/2,
10350 (
float)c->
y + (
float)c->
h/2), (
float)c->
w/2, c->
color,
10355 nk_draw_list_fill_circle(&ctx->draw_list,
nk_vec2((
float)c->
x + (
float)c->
w/2,
10356 (
float)c->
y + (
float)c->
h/2), (
float)c->
w/2, c->
color,
10361 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy));
10362 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy), c->
r,
10364 nk_draw_list_path_stroke(&ctx->draw_list, c->
color, NK_STROKE_CLOSED, c->
line_thickness);
10368 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy));
10369 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->
cx, c->
cy), c->
r,
10371 nk_draw_list_path_fill(&ctx->draw_list, c->
color);
10375 nk_draw_list_stroke_triangle(&ctx->draw_list,
nk_vec2(t->
a.
x, t->
a.
y),
10381 nk_draw_list_fill_triangle(&ctx->draw_list,
nk_vec2(t->
a.
x, t->
a.
y),
10389 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10391 nk_draw_list_path_stroke(&ctx->draw_list, p->
color, NK_STROKE_CLOSED, p->
line_thickness);
10398 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10400 nk_draw_list_path_fill(&ctx->draw_list, p->
color);
10407 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
10413 nk_draw_list_add_text(&ctx->draw_list, t->
font,
nk_rect(t->
x, t->
y, t->
w, t->
h),
10418 nk_draw_list_add_image(&ctx->draw_list, i->
img,
nk_rect(i->
x, i->
y, i->
w, i->
h), i->
col);
10432 NK_API const struct nk_draw_command*
10433 nk__draw_begin(
const struct nk_context *ctx,
10436 return nk__draw_list_begin(&ctx->draw_list, buffer);
10438 NK_API const struct nk_draw_command*
10441 return nk__draw_list_end(&ctx->draw_list, buffer);
10443 NK_API const struct nk_draw_command*
10444 nk__draw_next(
const struct nk_draw_command *cmd,
10447 return nk__draw_list_next(cmd, buffer, &ctx->draw_list);
10455 #ifdef NK_INCLUDE_FONT_BAKING 10463 #define NK_RP__MAXVAL 0xffff 10464 typedef unsigned short nk_rp_coord;
10466 struct nk_rp_rect {
10477 struct nk_rp_node {
10479 struct nk_rp_node *next;
10482 struct nk_rp_context {
10489 struct nk_rp_node *active_head;
10490 struct nk_rp_node *free_head;
10491 struct nk_rp_node extra[2];
10495 struct nk_rp__findresult {
10497 struct nk_rp_node **prev_link;
10500 enum NK_RP_HEURISTIC {
10501 NK_RP_HEURISTIC_Skyline_default=0,
10502 NK_RP_HEURISTIC_Skyline_BL_sortHeight = NK_RP_HEURISTIC_Skyline_default,
10503 NK_RP_HEURISTIC_Skyline_BF_sortHeight
10505 enum NK_RP_INIT_STATE{NK_RP__INIT_skyline = 1};
10508 nk_rp_setup_allow_out_of_mem(
struct nk_rp_context *context,
int allow_out_of_mem)
10510 if (allow_out_of_mem)
10515 context->align = 1;
10523 context->align = (context->width + context->num_nodes-1) / context->num_nodes;
10527 nk_rp_init_target(
struct nk_rp_context *context,
int width,
int height,
10528 struct nk_rp_node *nodes,
int num_nodes)
10531 #ifndef STBRP_LARGE_RECTS 10532 NK_ASSERT(width <= 0xffff && height <= 0xffff);
10535 for (i=0; i < num_nodes-1; ++i)
10536 nodes[i].next = &nodes[i+1];
10538 context->init_mode = NK_RP__INIT_skyline;
10539 context->heuristic = NK_RP_HEURISTIC_Skyline_default;
10540 context->free_head = &nodes[0];
10541 context->active_head = &context->extra[0];
10542 context->width = width;
10543 context->height = height;
10544 context->num_nodes = num_nodes;
10545 nk_rp_setup_allow_out_of_mem(context, 0);
10548 context->extra[0].x = 0;
10549 context->extra[0].y = 0;
10550 context->extra[0].next = &context->extra[1];
10551 context->extra[1].x = (nk_rp_coord) width;
10552 context->extra[1].y = 65535;
10553 context->extra[1].next = 0;
10557 nk_rp__skyline_find_min_y(
struct nk_rp_context *c,
struct nk_rp_node *first,
10558 int x0,
int width,
int *pwaste)
10560 struct nk_rp_node *node = first;
10561 int x1 = x0 + width;
10562 int min_y, visited_width, waste_area;
10563 NK_ASSERT(first->x <= x0);
10566 NK_ASSERT(node->next->x > x0);
10568 NK_ASSERT(node->x <= x0);
10573 while (node->x < x1)
10575 if (node->y > min_y) {
10579 waste_area += visited_width * (node->y - min_y);
10583 visited_width += node->next->x - x0;
10585 visited_width += node->next->x - node->x;
10588 int under_width = node->next->x - node->x;
10589 if (under_width + visited_width > width)
10590 under_width = width - visited_width;
10591 waste_area += under_width * (min_y - node->y);
10592 visited_width += under_width;
10596 *pwaste = waste_area;
10600 nk_rp__skyline_find_best_pos(struct nk_rp_context *c,
int width,
int height)
10602 int best_waste = (1<<30), best_x, best_y = (1 << 30);
10603 struct nk_rp__findresult fr;
10604 struct nk_rp_node **prev, *node, *tail, **best = 0;
10607 width = (width + c->align - 1);
10608 width -= width % c->align;
10609 NK_ASSERT(width % c->align == 0);
10611 node = c->active_head;
10612 prev = &c->active_head;
10613 while (node->x + width <= c->width) {
10615 y = nk_rp__skyline_find_min_y(c, node, node->x, width, &waste);
10617 if (c->heuristic == NK_RP_HEURISTIC_Skyline_BL_sortHeight) {
10625 if (y + height <= c->height) {
10627 if (y < best_y || (y == best_y && waste < best_waste)) {
10629 best_waste = waste;
10634 prev = &node->next;
10637 best_x = (best == 0) ? 0 : (*best)->x;
10655 if (c->heuristic == NK_RP_HEURISTIC_Skyline_BF_sortHeight)
10657 tail = c->active_head;
10658 node = c->active_head;
10659 prev = &c->active_head;
10661 while (tail->x < width)
10665 int xpos = tail->x - width;
10667 NK_ASSERT(xpos >= 0);
10669 while (node->next->x <= xpos) {
10670 prev = &node->next;
10673 NK_ASSERT(node->next->x > xpos && node->x <= xpos);
10674 y = nk_rp__skyline_find_min_y(c, node, xpos, width, &waste);
10675 if (y + height < c->height) {
10677 if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
10679 NK_ASSERT(y <= best_y);
10681 best_waste = waste;
10689 fr.prev_link = best;
10695 nk_rp__skyline_pack_rectangle(struct nk_rp_context *context,
int width,
int height)
10698 struct nk_rp__findresult res = nk_rp__skyline_find_best_pos(context, width, height);
10699 struct nk_rp_node *node, *cur;
10705 if (res.prev_link == 0 || res.y + height > context->height || context->free_head == 0) {
10711 node = context->free_head;
10712 node->x = (nk_rp_coord) res.x;
10713 node->y = (nk_rp_coord) (res.y + height);
10715 context->free_head = node->next;
10720 cur = *res.prev_link;
10721 if (cur->x < res.x) {
10723 struct nk_rp_node *next = cur->next;
10727 *res.prev_link = node;
10732 while (cur->next && cur->next->x <= res.x + width) {
10733 struct nk_rp_node *next = cur->next;
10735 cur->next = context->free_head;
10736 context->free_head = cur;
10742 if (cur->x < res.x + width)
10743 cur->x = (nk_rp_coord) (res.x + width);
10747 nk_rect_height_compare(
const void *a,
const void *b)
10749 const struct nk_rp_rect *p = (
const struct nk_rp_rect *) a;
10750 const struct nk_rp_rect *q = (
const struct nk_rp_rect *) b;
10755 return (p->w > q->w) ? -1 : (p->w < q->w);
10758 nk_rect_original_order(
const void *a,
const void *b)
10760 const struct nk_rp_rect *p = (
const struct nk_rp_rect *) a;
10761 const struct nk_rp_rect *q = (
const struct nk_rp_rect *) b;
10762 return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
10765 nk_rp_qsort(
struct nk_rp_rect *array,
unsigned int len,
int(*cmp)(
const void*,
const void*))
10768 #define NK_MAX_SORT_STACK 64 10769 unsigned right, left = 0, stack[NK_MAX_SORT_STACK], pos = 0;
10770 unsigned seed = len/2 * 69069+1;
10772 for (; left+1 < len; len++) {
10773 struct nk_rp_rect pivot, tmp;
10774 if (pos == NK_MAX_SORT_STACK) len = stack[pos = 0];
10775 pivot = array[left+seed%(len-left)];
10776 seed = seed * 69069 + 1;
10777 stack[pos++] = len;
10778 for (right = left-1;;) {
10779 while (cmp(&array[++right], &pivot) < 0);
10780 while (cmp(&pivot, &array[--len]) < 0);
10781 if (right >= len)
break;
10782 tmp = array[right];
10783 array[right] = array[len];
10787 if (pos == 0)
break;
10789 len = stack[--pos];
10791 #undef NK_MAX_SORT_STACK 10794 nk_rp_pack_rects(
struct nk_rp_context *context,
struct nk_rp_rect *rects,
int num_rects)
10798 for (i=0; i < num_rects; ++i) {
10799 rects[i].was_packed = i;
10803 nk_rp_qsort(rects, (
unsigned)num_rects, nk_rect_height_compare);
10805 for (i=0; i < num_rects; ++i) {
10806 struct nk_rp__findresult fr = nk_rp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
10807 if (fr.prev_link) {
10808 rects[i].x = (nk_rp_coord) fr.x;
10809 rects[i].y = (nk_rp_coord) fr.y;
10811 rects[i].x = rects[i].y = NK_RP__MAXVAL;
10816 nk_rp_qsort(rects, (
unsigned)num_rects, nk_rect_original_order);
10819 for (i=0; i < num_rects; ++i)
10820 rects[i].was_packed = !(rects[i].x == NK_RP__MAXVAL && rects[i].y == NK_RP__MAXVAL);
10831 #define NK_TT_MAX_OVERSAMPLE 8 10832 #define NK_TT__OVER_MASK (NK_TT_MAX_OVERSAMPLE-1) 10834 struct nk_tt_bakedchar {
10835 unsigned short x0,y0,x1,y1;
10837 float xoff,yoff,xadvance;
10840 struct nk_tt_aligned_quad{
10845 struct nk_tt_packedchar {
10846 unsigned short x0,y0,x1,y1;
10848 float xoff,yoff,xadvance;
10852 struct nk_tt_pack_range {
10854 int first_unicode_codepoint_in_range;
10856 int *array_of_unicode_codepoints;
10859 struct nk_tt_packedchar *chardata_for_range;
10860 unsigned char h_oversample, v_oversample;
10864 struct nk_tt_pack_context {
10868 int stride_in_bytes;
10870 unsigned int h_oversample, v_oversample;
10871 unsigned char *pixels;
10875 struct nk_tt_fontinfo {
10876 const unsigned char* data;
10879 int loca,head,glyf,hhea,hmtx,kern;
10881 int indexToLocFormat;
10890 struct nk_tt_vertex {
10892 unsigned char type,padding;
10895 struct nk_tt__bitmap{
10897 unsigned char *pixels;
10900 struct nk_tt__hheap_chunk {
10901 struct nk_tt__hheap_chunk *next;
10903 struct nk_tt__hheap {
10905 struct nk_tt__hheap_chunk *head;
10907 int num_remaining_in_head_chunk;
10910 struct nk_tt__edge {
10911 float x0,y0, x1,y1;
10915 struct nk_tt__active_edge {
10916 struct nk_tt__active_edge *next;
10922 struct nk_tt__point {
float x,y;};
10924 #define NK_TT_MACSTYLE_DONTCARE 0 10925 #define NK_TT_MACSTYLE_BOLD 1 10926 #define NK_TT_MACSTYLE_ITALIC 2 10927 #define NK_TT_MACSTYLE_UNDERSCORE 4 10928 #define NK_TT_MACSTYLE_NONE 8 10932 NK_TT_PLATFORM_ID_UNICODE =0,
10933 NK_TT_PLATFORM_ID_MAC =1,
10934 NK_TT_PLATFORM_ID_ISO =2,
10935 NK_TT_PLATFORM_ID_MICROSOFT =3
10939 NK_TT_UNICODE_EID_UNICODE_1_0 =0,
10940 NK_TT_UNICODE_EID_UNICODE_1_1 =1,
10941 NK_TT_UNICODE_EID_ISO_10646 =2,
10942 NK_TT_UNICODE_EID_UNICODE_2_0_BMP=3,
10943 NK_TT_UNICODE_EID_UNICODE_2_0_FULL=4
10947 NK_TT_MS_EID_SYMBOL =0,
10948 NK_TT_MS_EID_UNICODE_BMP =1,
10949 NK_TT_MS_EID_SHIFTJIS =2,
10950 NK_TT_MS_EID_UNICODE_FULL =10
10954 NK_TT_MAC_EID_ROMAN =0, NK_TT_MAC_EID_ARABIC =4,
10955 NK_TT_MAC_EID_JAPANESE =1, NK_TT_MAC_EID_HEBREW =5,
10956 NK_TT_MAC_EID_CHINESE_TRAD =2, NK_TT_MAC_EID_GREEK =6,
10957 NK_TT_MAC_EID_KOREAN =3, NK_TT_MAC_EID_RUSSIAN =7
10962 NK_TT_MS_LANG_ENGLISH =0x0409, NK_TT_MS_LANG_ITALIAN =0x0410,
10963 NK_TT_MS_LANG_CHINESE =0x0804, NK_TT_MS_LANG_JAPANESE =0x0411,
10964 NK_TT_MS_LANG_DUTCH =0x0413, NK_TT_MS_LANG_KOREAN =0x0412,
10965 NK_TT_MS_LANG_FRENCH =0x040c, NK_TT_MS_LANG_RUSSIAN =0x0419,
10966 NK_TT_MS_LANG_GERMAN =0x0407, NK_TT_MS_LANG_SPANISH =0x0409,
10967 NK_TT_MS_LANG_HEBREW =0x040d, NK_TT_MS_LANG_SWEDISH =0x041D
10971 NK_TT_MAC_LANG_ENGLISH =0 , NK_TT_MAC_LANG_JAPANESE =11,
10972 NK_TT_MAC_LANG_ARABIC =12, NK_TT_MAC_LANG_KOREAN =23,
10973 NK_TT_MAC_LANG_DUTCH =4 , NK_TT_MAC_LANG_RUSSIAN =32,
10974 NK_TT_MAC_LANG_FRENCH =1 , NK_TT_MAC_LANG_SPANISH =6 ,
10975 NK_TT_MAC_LANG_GERMAN =2 , NK_TT_MAC_LANG_SWEDISH =5 ,
10976 NK_TT_MAC_LANG_HEBREW =10, NK_TT_MAC_LANG_CHINESE_SIMPLIFIED =33,
10977 NK_TT_MAC_LANG_ITALIAN =3 , NK_TT_MAC_LANG_CHINESE_TRAD =19
10980 #define nk_ttBYTE(p) (* (const nk_byte *) (p)) 10981 #define nk_ttCHAR(p) (* (const char *) (p)) 10983 #if defined(NK_BIGENDIAN) && !defined(NK_ALLOW_UNALIGNED_TRUETYPE) 10984 #define nk_ttUSHORT(p) (* (nk_ushort *) (p)) 10985 #define nk_ttSHORT(p) (* (nk_short *) (p)) 10986 #define nk_ttULONG(p) (* (nk_uint *) (p)) 10987 #define nk_ttLONG(p) (* (nk_int *) (p)) 10991 static nk_uint nk_ttULONG(
const nk_byte *p) {
return (
nk_uint)((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]); }
10994 #define nk_tt_tag4(p,c0,c1,c2,c3)\ 10995 ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) 10996 #define nk_tt_tag(p,str) nk_tt_tag4(p,str[0],str[1],str[2],str[3]) 10999 int glyph_index,
struct nk_tt_vertex **pvertices);
11002 nk_tt__find_table(
const nk_byte *data,
nk_uint fontstart,
const char *tag)
11005 nk_int num_tables = nk_ttUSHORT(data+fontstart+4);
11006 nk_uint tabledir = fontstart + 12;
11008 for (i = 0; i < num_tables; ++i) {
11010 if (nk_tt_tag(data+loc+0, tag))
11011 return nk_ttULONG(data+loc+8);
11016 nk_tt_InitFont(
struct nk_tt_fontinfo *info,
const unsigned char *data2,
int fontstart)
11023 info->fontstart = fontstart;
11025 cmap = nk_tt__find_table(data, (
nk_uint)fontstart,
"cmap");
11026 info->loca = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"loca");
11027 info->head = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"head");
11028 info->glyf = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"glyf");
11029 info->hhea = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"hhea");
11030 info->hmtx = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"hmtx");
11031 info->kern = (int)nk_tt__find_table(data, (
nk_uint)fontstart,
"kern");
11032 if (!cmap || !info->loca || !info->head || !info->glyf || !info->hhea || !info->hmtx)
11035 t = nk_tt__find_table(data, (
nk_uint)fontstart,
"maxp");
11036 if (t) info->numGlyphs = nk_ttUSHORT(data+t+4);
11037 else info->numGlyphs = 0xffff;
11042 numTables = nk_ttUSHORT(data + cmap + 2);
11043 info->index_map = 0;
11044 for (i=0; i < numTables; ++i)
11048 switch(nk_ttUSHORT(data+encoding_record)) {
11049 case NK_TT_PLATFORM_ID_MICROSOFT:
11050 switch (nk_ttUSHORT(data+encoding_record+2)) {
11051 case NK_TT_MS_EID_UNICODE_BMP:
11052 case NK_TT_MS_EID_UNICODE_FULL:
11054 info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4));
11058 case NK_TT_PLATFORM_ID_UNICODE:
11061 info->index_map = (int)(cmap + nk_ttULONG(data+encoding_record+4));
11066 if (info->index_map == 0)
11068 info->indexToLocFormat = nk_ttUSHORT(data+info->head + 50);
11072 nk_tt_FindGlyphIndex(
const struct nk_tt_fontinfo *info,
int unicode_codepoint)
11074 const nk_byte *data = info->data;
11077 nk_ushort format = nk_ttUSHORT(data + index_map + 0);
11079 nk_int bytes = nk_ttUSHORT(data + index_map + 2);
11080 if (unicode_codepoint < bytes-6)
11081 return nk_ttBYTE(data + index_map + 6 + unicode_codepoint);
11083 }
else if (format == 6) {
11084 nk_uint first = nk_ttUSHORT(data + index_map + 6);
11085 nk_uint count = nk_ttUSHORT(data + index_map + 8);
11086 if ((
nk_uint) unicode_codepoint >= first && (
nk_uint) unicode_codepoint < first+count)
11087 return nk_ttUSHORT(data + index_map + 10 + (unicode_codepoint - (
int)first)*2);
11089 }
else if (format == 2) {
11092 }
else if (format == 4) {
11093 nk_ushort segcount = nk_ttUSHORT(data+index_map+6) >> 1;
11094 nk_ushort searchRange = nk_ttUSHORT(data+index_map+8) >> 1;
11095 nk_ushort entrySelector = nk_ttUSHORT(data+index_map+10);
11096 nk_ushort rangeShift = nk_ttUSHORT(data+index_map+12) >> 1;
11099 nk_uint endCount = index_map + 14;
11102 if (unicode_codepoint > 0xffff)
11107 if (unicode_codepoint >= nk_ttUSHORT(data + search + rangeShift*2))
11108 search += (
nk_uint)(rangeShift*2);
11112 while (entrySelector) {
11115 end = nk_ttUSHORT(data + search + searchRange*2);
11116 if (unicode_codepoint > end)
11117 search += (
nk_uint)(searchRange*2);
11126 NK_ASSERT(unicode_codepoint <= nk_ttUSHORT(data + endCount + 2*item));
11127 start = nk_ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
11128 if (unicode_codepoint < start)
11131 offset = nk_ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
11133 return (
nk_ushort) (unicode_codepoint + nk_ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));
11135 return nk_ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
11137 }
else if (format == 12 || format == 13) {
11138 nk_uint ngroups = nk_ttULONG(data+index_map+12);
11140 low = 0; high = (
nk_int)ngroups;
11142 while (low < high) {
11143 nk_int mid = low + ((high-low) >> 1);
11144 nk_uint start_char = nk_ttULONG(data+index_map+16+mid*12);
11145 nk_uint end_char = nk_ttULONG(data+index_map+16+mid*12+4);
11146 if ((
nk_uint) unicode_codepoint < start_char)
11148 else if ((
nk_uint) unicode_codepoint > end_char)
11151 nk_uint start_glyph = nk_ttULONG(data+index_map+16+mid*12+8);
11153 return (
int)start_glyph + (int)unicode_codepoint - (
int)start_char;
11155 return (
int)start_glyph;
11174 nk_tt__GetGlyfOffset(
const struct nk_tt_fontinfo *info,
int glyph_index)
11177 if (glyph_index >= info->numGlyphs)
return -1;
11178 if (info->indexToLocFormat >= 2)
return -1;
11180 if (info->indexToLocFormat == 0) {
11181 g1 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2) * 2;
11182 g2 = info->glyf + nk_ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2;
11184 g1 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4);
11185 g2 = info->glyf + (int)nk_ttULONG (info->data + info->loca + glyph_index * 4 + 4);
11187 return g1==g2 ? -1 : g1;
11190 nk_tt_GetGlyphBox(
const struct nk_tt_fontinfo *info,
int glyph_index,
11191 int *x0,
int *y0,
int *x1,
int *y1)
11193 int g = nk_tt__GetGlyfOffset(info, glyph_index);
11194 if (g < 0)
return 0;
11196 if (x0) *x0 = nk_ttSHORT(info->data + g + 2);
11197 if (y0) *y0 = nk_ttSHORT(info->data + g + 4);
11198 if (x1) *x1 = nk_ttSHORT(info->data + g + 6);
11199 if (y1) *y1 = nk_ttSHORT(info->data + g + 8);
11203 nk_tt__close_shape(
struct nk_tt_vertex *vertices,
int num_vertices,
int was_off,
11208 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy);
11209 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, sx,sy,scx,scy);
11212 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve,sx,sy,cx,cy);
11214 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline,sx,sy,0,0);
11216 return num_vertices;
11219 nk_tt_GetGlyphShape(
const struct nk_tt_fontinfo *info,
struct nk_allocator *alloc,
11220 int glyph_index,
struct nk_tt_vertex **pvertices)
11223 const nk_byte *endPtsOfContours;
11224 const nk_byte *data = info->data;
11225 struct nk_tt_vertex *vertices=0;
11226 int num_vertices=0;
11227 int g = nk_tt__GetGlyfOffset(info, glyph_index);
11230 if (g < 0)
return 0;
11231 numberOfContours = nk_ttSHORT(data + g);
11232 if (numberOfContours > 0) {
11234 nk_int ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0;
11235 nk_int x,y,cx,cy,sx,sy, scx,scy;
11237 endPtsOfContours = (data + g + 10);
11238 ins = nk_ttUSHORT(data + g + 10 + numberOfContours * 2);
11239 points = data + g + 10 + numberOfContours * 2 + 2 + ins;
11241 n = 1+nk_ttUSHORT(endPtsOfContours + numberOfContours*2-2);
11242 m = n + 2*numberOfContours;
11243 vertices = (
struct nk_tt_vertex *)alloc->
alloc(alloc->
userdata, 0, (
nk_size)m *
sizeof(vertices[0]));
11256 for (i=0; i < n; ++i) {
11257 if (flagcount == 0) {
11260 flagcount = *points++;
11261 }
else --flagcount;
11262 vertices[off+i].type = flags;
11267 for (i=0; i < n; ++i) {
11268 flags = vertices[off+i].type;
11271 x += (flags & 16) ? dx : -dx;
11273 if (!(flags & 16)) {
11274 x = x + (
nk_short) (points[0]*256 + points[1]);
11283 for (i=0; i < n; ++i) {
11284 flags = vertices[off+i].type;
11287 y += (flags & 32) ? dy : -dy;
11289 if (!(flags & 32)) {
11290 y = y + (
nk_short) (points[0]*256 + points[1]);
11299 sx = sy = cx = cy = scx = scy = 0;
11300 for (i=0; i < n; ++i)
11302 flags = vertices[off+i].type;
11306 if (next_move == i) {
11308 num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
11311 start_off = !(flags & 1);
11317 if (!(vertices[off+i+1].type & 1)) {
11319 sx = (x + (
nk_int) vertices[off+i+1].x) >> 1;
11320 sy = (y + (
nk_int) vertices[off+i+1].y) >> 1;
11323 sx = (
nk_int) vertices[off+i+1].x;
11324 sy = (
nk_int) vertices[off+i+1].y;
11331 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vmove,sx,sy,0,0);
11333 next_move = 1 + nk_ttUSHORT(endPtsOfContours+j*2);
11339 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy);
11345 nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vcurve, x,y, cx, cy);
11346 else nk_tt_setvertex(&vertices[num_vertices++], NK_TT_vline, x,y,0,0);
11351 num_vertices = nk_tt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
11352 }
else if (numberOfContours == -1) {
11355 const nk_byte *comp = data + g + 10;
11362 int comp_num_verts = 0, i;
11363 struct nk_tt_vertex *comp_verts = 0, *tmp = 0;
11364 float mtx[6] = {1,0,0,1,0,0}, m, n;
11366 flags = (
nk_ushort)nk_ttSHORT(comp); comp+=2;
11367 gidx = (
nk_ushort)nk_ttSHORT(comp); comp+=2;
11371 mtx[4] = nk_ttSHORT(comp); comp+=2;
11372 mtx[5] = nk_ttSHORT(comp); comp+=2;
11374 mtx[4] = nk_ttCHAR(comp); comp+=1;
11375 mtx[5] = nk_ttCHAR(comp); comp+=1;
11381 if (flags & (1<<3)) {
11382 mtx[0] = mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11383 mtx[1] = mtx[2] = 0;
11384 }
else if (flags & (1<<6)) {
11385 mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11386 mtx[1] = mtx[2] = 0;
11387 mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11388 }
else if (flags & (1<<7)) {
11389 mtx[0] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11390 mtx[1] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11391 mtx[2] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11392 mtx[3] = nk_ttSHORT(comp)/16384.0f; comp+=2;
11396 m = (float) NK_SQRT(mtx[0]*mtx[0] + mtx[1]*mtx[1]);
11397 n = (float) NK_SQRT(mtx[2]*mtx[2] + mtx[3]*mtx[3]);
11400 comp_num_verts = nk_tt_GetGlyphShape(info, alloc, gidx, &comp_verts);
11401 if (comp_num_verts > 0)
11404 for (i = 0; i < comp_num_verts; ++i) {
11405 struct nk_tt_vertex* v = &comp_verts[i];
11408 v->x = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4]));
11409 v->y = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5]));
11411 v->cx = (short)(m * (mtx[0]*x + mtx[2]*y + mtx[4]));
11412 v->cy = (short)(n * (mtx[1]*x + mtx[3]*y + mtx[5]));
11415 tmp = (
struct nk_tt_vertex*)alloc->
alloc(alloc->
userdata, 0,
11416 (
nk_size)(num_vertices+comp_num_verts)*
sizeof(
struct nk_tt_vertex));
11419 if (comp_verts) alloc->
free(alloc->
userdata, comp_verts);
11422 if (num_vertices > 0) NK_MEMCPY(tmp, vertices, (
nk_size)num_vertices*
sizeof(
struct nk_tt_vertex));
11423 NK_MEMCPY(tmp+num_vertices, comp_verts, (
nk_size)comp_num_verts*
sizeof(
struct nk_tt_vertex));
11427 num_vertices += comp_num_verts;
11430 more = flags & (1<<5);
11432 }
else if (numberOfContours < 0) {
11438 *pvertices = vertices;
11439 return num_vertices;
11442 nk_tt_GetGlyphHMetrics(
const struct nk_tt_fontinfo *info,
int glyph_index,
11443 int *advanceWidth,
int *leftSideBearing)
11445 nk_ushort numOfLongHorMetrics = nk_ttUSHORT(info->data+info->hhea + 34);
11446 if (glyph_index < numOfLongHorMetrics) {
11448 *advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index);
11449 if (leftSideBearing)
11450 *leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*glyph_index + 2);
11453 *advanceWidth = nk_ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1));
11454 if (leftSideBearing)
11455 *leftSideBearing = nk_ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));
11459 nk_tt_GetFontVMetrics(
const struct nk_tt_fontinfo *info,
11460 int *ascent,
int *descent,
int *lineGap)
11462 if (ascent ) *ascent = nk_ttSHORT(info->data+info->hhea + 4);
11463 if (descent) *descent = nk_ttSHORT(info->data+info->hhea + 6);
11464 if (lineGap) *lineGap = nk_ttSHORT(info->data+info->hhea + 8);
11467 nk_tt_ScaleForPixelHeight(
const struct nk_tt_fontinfo *info,
float height)
11469 int fheight = nk_ttSHORT(info->data + info->hhea + 4) - nk_ttSHORT(info->data + info->hhea + 6);
11470 return (
float) height / (float)fheight;
11473 nk_tt_ScaleForMappingEmToPixels(
const struct nk_tt_fontinfo *info,
float pixels)
11475 int unitsPerEm = nk_ttUSHORT(info->data + info->head + 18);
11476 return pixels / (float)unitsPerEm;
11483 nk_tt_GetGlyphBitmapBoxSubpixel(
const struct nk_tt_fontinfo *font,
11484 int glyph,
float scale_x,
float scale_y,
float shift_x,
float shift_y,
11485 int *ix0,
int *iy0,
int *ix1,
int *iy1)
11488 if (!nk_tt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {
11496 if (ix0) *ix0 = nk_ifloorf((
float)x0 * scale_x + shift_x);
11497 if (iy0) *iy0 = nk_ifloorf((
float)-y1 * scale_y + shift_y);
11498 if (ix1) *ix1 = nk_iceilf ((
float)x1 * scale_x + shift_x);
11499 if (iy1) *iy1 = nk_iceilf ((
float)-y0 * scale_y + shift_y);
11503 nk_tt_GetGlyphBitmapBox(
const struct nk_tt_fontinfo *font,
int glyph,
11504 float scale_x,
float scale_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1)
11506 nk_tt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);
11513 nk_tt__hheap_alloc(
struct nk_tt__hheap *hh,
nk_size size)
11515 if (hh->first_free) {
11516 void *p = hh->first_free;
11517 hh->first_free = * (
void **) p;
11520 if (hh->num_remaining_in_head_chunk == 0) {
11521 int count = (size < 32 ? 2000 : size < 128 ? 800 : 100);
11522 struct nk_tt__hheap_chunk *c = (
struct nk_tt__hheap_chunk *)
11523 hh->alloc.alloc(hh->alloc.userdata, 0,
11524 sizeof(
struct nk_tt__hheap_chunk) + size * (
nk_size)count);
11525 if (c == 0)
return 0;
11526 c->next = hh->head;
11528 hh->num_remaining_in_head_chunk = count;
11530 --hh->num_remaining_in_head_chunk;
11531 return (
char *) (hh->head) + size * (
nk_size)hh->num_remaining_in_head_chunk;
11535 nk_tt__hheap_free(
struct nk_tt__hheap *hh,
void *p)
11537 *(
void **) p = hh->first_free;
11538 hh->first_free = p;
11541 nk_tt__hheap_cleanup(
struct nk_tt__hheap *hh)
11543 struct nk_tt__hheap_chunk *c = hh->head;
11545 struct nk_tt__hheap_chunk *n = c->next;
11546 hh->alloc.free(hh->alloc.userdata, c);
11551 nk_tt__new_active(
struct nk_tt__hheap *hh,
struct nk_tt__edge *e,
11552 int off_x,
float start_point)
11554 struct nk_tt__active_edge *z = (
struct nk_tt__active_edge *)
11555 nk_tt__hheap_alloc(hh,
sizeof(*z));
11556 float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
11560 z->fdy = (dxdy != 0) ? (1/dxdy): 0;
11561 z->fx = e->x0 + dxdy * (start_point - e->y0);
11562 z->fx -= (float)off_x;
11563 z->direction = e->invert ? 1.0f : -1.0f;
11570 nk_tt__handle_clipped_edge(
float *scanline,
int x,
struct nk_tt__active_edge *e,
11571 float x0,
float y0,
float x1,
float y1)
11573 if (y0 == y1)
return;
11574 NK_ASSERT(y0 < y1);
11575 NK_ASSERT(e->sy <= e->ey);
11576 if (y0 > e->ey)
return;
11577 if (y1 < e->sy)
return;
11579 x0 += (x1-x0) * (e->sy - y0) / (y1-y0);
11583 x1 += (x1-x0) * (e->ey - y1) / (y1-y0);
11587 if (x0 == x) NK_ASSERT(x1 <= x+1);
11588 else if (x0 == x+1) NK_ASSERT(x1 >= x);
11589 else if (x0 <= x) NK_ASSERT(x1 <= x);
11590 else if (x0 >= x+1) NK_ASSERT(x1 >= x+1);
11591 else NK_ASSERT(x1 >= x && x1 <= x+1);
11593 if (x0 <= x && x1 <= x)
11594 scanline[x] += e->direction * (y1-y0);
11595 else if (x0 >= x+1 && x1 >= x+1);
11597 NK_ASSERT(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1);
11599 scanline[x] += (float)e->direction * (
float)(y1-y0) * (1.0f-((x0-(
float)x)+(x1-(float)x))/2.0f);
11603 nk_tt__fill_active_edges_new(
float *scanline,
float *scanline_fill,
int len,
11604 struct nk_tt__active_edge *e,
float y_top)
11606 float y_bottom = y_top+1;
11611 NK_ASSERT(e->ey >= y_top);
11616 nk_tt__handle_clipped_edge(scanline,(
int) x0,e, x0,y_top, x0,y_bottom);
11617 nk_tt__handle_clipped_edge(scanline_fill-1,(
int) x0+1,e, x0,y_top, x0,y_bottom);
11619 nk_tt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom);
11625 float xb = x0 + dx;
11626 float x_top, x_bottom;
11629 NK_ASSERT(e->sy <= y_bottom && e->ey >= y_top);
11634 if (e->sy > y_top) {
11635 x_top = x0 + dx * (e->sy - y_top);
11642 if (e->ey < y_bottom) {
11643 x_bottom = x0 + dx * (e->ey - y_top);
11650 if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len)
11653 if ((
int) x_top == (int) x_bottom) {
11656 int x = (int) x_top;
11658 NK_ASSERT(x >= 0 && x < len);
11659 scanline[x] += e->direction * (1.0f-(((float)x_top - (
float)x) + ((
float)x_bottom-(float)x))/2.0f) * (float)height;
11660 scanline_fill[x] += e->direction * (float)height;
11663 float y_crossing, step, sign, area;
11665 if (x_top > x_bottom)
11669 y0 = y_bottom - (y0 - y_top);
11670 y1 = y_bottom - (y1 - y_top);
11671 t = y0; y0 = y1; y1 = t;
11672 t = x_bottom; x_bottom = x_top; x_top = t;
11675 t = x0; x0 = xb; xb = t;
11679 x2 = (int) x_bottom;
11681 y_crossing = ((float)x1+1 - (
float)x0) * (
float)dy + (float)y_top;
11683 sign = e->direction;
11685 area = sign * (y_crossing-y0);
11687 scanline[x1] += area * (1.0f-((float)((
float)x_top - (float)x1)+(float)(x1+1-x1))/2.0f);
11690 for (x = x1+1; x < x2; ++x) {
11691 scanline[x] += area + step/2;
11694 y_crossing += (float)dy * (
float)(x2 - (x1+1));
11696 scanline[x2] += area + sign * (1.0f-((float)(x2-x2)+((float)x_bottom-(
float)x2))/2.0f) * (y1-y_crossing);
11697 scanline_fill[x2] += sign * (y1-y0);
11707 for (x=0; x < len; ++x)
11724 float x1 = (float) (x);
11725 float x2 = (float) (x+1);
11727 float y3 = y_bottom;
11730 yb = ((float)x - x0) / dx + y_top;
11731 y2 = ((float)x+1 - x0) / dx + y_top;
11733 if (x0 < x1 && x3 > x2) {
11734 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11735 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x2,y2);
11736 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11737 }
else if (x3 < x1 && x0 > x2) {
11738 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11739 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x1,yb);
11740 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11741 }
else if (x0 < x1 && x3 > x1) {
11742 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11743 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11744 }
else if (x3 < x1 && x0 > x1) {
11745 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x1,yb);
11746 nk_tt__handle_clipped_edge(scanline,x,e, x1,yb, x3,y3);
11747 }
else if (x0 < x2 && x3 > x2) {
11748 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11749 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11750 }
else if (x3 < x2 && x0 > x2) {
11751 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x2,y2);
11752 nk_tt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
11754 nk_tt__handle_clipped_edge(scanline,x,e, x0,ya, x3,y3);
11763 nk_tt__rasterize_sorted_edges(
struct nk_tt__bitmap *result,
struct nk_tt__edge *e,
11764 int n,
int vsubsample,
int off_x,
int off_y,
struct nk_allocator *alloc)
11767 struct nk_tt__hheap hh;
11768 struct nk_tt__active_edge *active = 0;
11770 float scanline_data[129], *scanline, *scanline2;
11776 if (result->w > 64)
11777 scanline = (
float *) alloc->
alloc(alloc->
userdata,0, (
nk_size)(result->w*2+1) *
sizeof(
float));
11778 else scanline = scanline_data;
11780 scanline2 = scanline + result->w;
11782 e[n].y0 = (float) (off_y + result->h) + 1;
11784 while (j < result->h)
11787 float scan_y_top = (float)y + 0.0f;
11788 float scan_y_bottom = (float)y + 1.0f;
11789 struct nk_tt__active_edge **step = &active;
11791 NK_MEMSET(scanline , 0, (
nk_size)result->w*
sizeof(scanline[0]));
11792 NK_MEMSET(scanline2, 0, (
nk_size)(result->w+1)*
sizeof(scanline[0]));
11797 struct nk_tt__active_edge * z = *step;
11798 if (z->ey <= scan_y_top) {
11800 NK_ASSERT(z->direction);
11802 nk_tt__hheap_free(&hh, z);
11804 step = &((*step)->next);
11809 while (e->y0 <= scan_y_bottom) {
11810 if (e->y0 != e->y1) {
11811 struct nk_tt__active_edge *z = nk_tt__new_active(&hh, e, off_x, scan_y_top);
11813 NK_ASSERT(z->ey >= scan_y_top);
11824 nk_tt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top);
11828 for (i=0; i < result->w; ++i) {
11831 sum += scanline2[i];
11832 k = scanline[i] + sum;
11833 k = (float)
NK_ABS(k) * 255.0f + 0.5f;
11835 if (m > 255) m = 255;
11836 result->pixels[j*result->stride + i] = (
unsigned char) m;
11842 struct nk_tt__active_edge *z = *step;
11844 step = &((*step)->next);
11849 nk_tt__hheap_cleanup(&hh);
11850 if (scanline != scanline_data)
11854 nk_tt__sort_edges_ins_sort(
struct nk_tt__edge *p,
int n)
11857 #define NK_TT__COMPARE(a,b) ((a)->y0 < (b)->y0) 11858 for (i=1; i < n; ++i) {
11859 struct nk_tt__edge t = p[i], *a = &t;
11862 struct nk_tt__edge *b = &p[j-1];
11863 int c = NK_TT__COMPARE(a,b);
11873 nk_tt__sort_edges_quicksort(
struct nk_tt__edge *p,
int n)
11877 struct nk_tt__edge t;
11878 int c01,c12,c,m,i,j;
11882 c01 = NK_TT__COMPARE(&p[0],&p[m]);
11883 c12 = NK_TT__COMPARE(&p[m],&p[n-1]);
11889 c = NK_TT__COMPARE(&p[0],&p[n-1]);
11892 z = (c == c12) ? 0 : n-1;
11911 if (!NK_TT__COMPARE(&p[i], &p[0]))
break;
11914 if (!NK_TT__COMPARE(&p[0], &p[j]))
break;
11930 nk_tt__sort_edges_quicksort(p,j);
11934 nk_tt__sort_edges_quicksort(p+i, n-i);
11940 nk_tt__sort_edges(
struct nk_tt__edge *p,
int n)
11942 nk_tt__sort_edges_quicksort(p, n);
11943 nk_tt__sort_edges_ins_sort(p, n);
11946 nk_tt__rasterize(
struct nk_tt__bitmap *result,
struct nk_tt__point *pts,
11947 int *wcount,
int windings,
float scale_x,
float scale_y,
11948 float shift_x,
float shift_y,
int off_x,
int off_y,
int invert,
11951 float y_scale_inv = invert ? -scale_y : scale_y;
11952 struct nk_tt__edge *e;
11954 int vsubsample = 1;
11959 for (i=0; i < windings; ++i)
11962 e = (
struct nk_tt__edge*)
11964 if (e == 0)
return;
11968 for (i=0; i < windings; ++i)
11970 struct nk_tt__point *p = pts + m;
11973 for (k=0; k < wcount[i]; j=k++) {
11976 if (p[j].y == p[k].y)
11981 if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) {
11985 e[n].x0 = p[a].x * scale_x + shift_x;
11986 e[n].y0 = (p[a].y * y_scale_inv + shift_y) * (
float)vsubsample;
11987 e[n].x1 = p[b].x * scale_x + shift_x;
11988 e[n].y1 = (p[b].y * y_scale_inv + shift_y) * (
float)vsubsample;
11995 nk_tt__sort_edges(e, n);
11997 nk_tt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, alloc);
12001 nk_tt__add_point(
struct nk_tt__point *points,
int n,
float x,
float y)
12003 if (!points)
return;
12008 nk_tt__tesselate_curve(
struct nk_tt__point *points,
int *num_points,
12009 float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
12010 float objspace_flatness_squared,
int n)
12015 float mx = (x0 + 2*x1 + x2)/4;
12016 float my = (y0 + 2*y1 + y2)/4;
12018 float dx = (x0+x2)/2 - mx;
12019 float dy = (y0+y2)/2 - my;
12024 if (dx*dx+dy*dy > objspace_flatness_squared) {
12025 nk_tt__tesselate_curve(points, num_points, x0,y0,
12026 (x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1);
12027 nk_tt__tesselate_curve(points, num_points, mx,my,
12028 (x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1);
12030 nk_tt__add_point(points, *num_points,x2,y2);
12031 *num_points = *num_points+1;
12036 nk_tt_FlattenCurves(
struct nk_tt_vertex *vertices,
int num_verts,
12037 float objspace_flatness,
int **contour_lengths,
int *num_contours,
12041 struct nk_tt__point *points=0;
12043 float objspace_flatness_squared = objspace_flatness * objspace_flatness;
12050 for (i=0; i < num_verts; ++i)
12051 if (vertices[i].type == NK_TT_vmove) ++n;
12054 if (n == 0)
return 0;
12056 *contour_lengths = (
int *)
12058 if (*contour_lengths == 0) {
12064 for (pass=0; pass < 2; ++pass)
12068 points = (
struct nk_tt__point *)
12070 if (points == 0)
goto error;
12075 for (i=0; i < num_verts; ++i)
12077 switch (vertices[i].type) {
12081 (*contour_lengths)[n] = num_points - start;
12083 start = num_points;
12085 x = vertices[i].x, y = vertices[i].y;
12086 nk_tt__add_point(points, num_points++, x,y);
12089 x = vertices[i].x, y = vertices[i].y;
12090 nk_tt__add_point(points, num_points++, x, y);
12093 nk_tt__tesselate_curve(points, &num_points, x,y,
12094 vertices[i].cx, vertices[i].cy,
12095 vertices[i].x, vertices[i].y,
12096 objspace_flatness_squared, 0);
12097 x = vertices[i].x, y = vertices[i].y;
12102 (*contour_lengths)[n] = num_points - start;
12109 *contour_lengths = 0;
12114 nk_tt_Rasterize(
struct nk_tt__bitmap *result,
float flatness_in_pixels,
12115 struct nk_tt_vertex *vertices,
int num_verts,
12116 float scale_x,
float scale_y,
float shift_x,
float shift_y,
12117 int x_off,
int y_off,
int invert,
struct nk_allocator *alloc)
12119 float scale = scale_x > scale_y ? scale_y : scale_x;
12120 int winding_count, *winding_lengths;
12121 struct nk_tt__point *windings = nk_tt_FlattenCurves(vertices, num_verts,
12122 flatness_in_pixels / scale, &winding_lengths, &winding_count, alloc);
12126 nk_tt__rasterize(result, windings, winding_lengths, winding_count,
12127 scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, alloc);
12133 nk_tt_MakeGlyphBitmapSubpixel(
const struct nk_tt_fontinfo *info,
unsigned char *output,
12134 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
12135 float shift_x,
float shift_y,
int glyph,
struct nk_allocator *alloc)
12138 struct nk_tt_vertex *vertices;
12139 int num_verts = nk_tt_GetGlyphShape(info, alloc, glyph, &vertices);
12140 struct nk_tt__bitmap gbm;
12142 nk_tt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x,
12143 shift_y, &ix0,&iy0,0,0);
12144 gbm.pixels = output;
12147 gbm.stride = out_stride;
12149 if (gbm.w && gbm.h)
12150 nk_tt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y,
12151 shift_x, shift_y, ix0,iy0, 1, alloc);
12159 nk_tt_PackBegin(
struct nk_tt_pack_context *spc,
unsigned char *pixels,
12160 int pw,
int ph,
int stride_in_bytes,
int padding,
struct nk_allocator *alloc)
12162 int num_nodes = pw - padding;
12163 struct nk_rp_context *context = (
struct nk_rp_context *)
12165 struct nk_rp_node *nodes = (
struct nk_rp_node*)
12168 if (context == 0 || nodes == 0) {
12169 if (context != 0) alloc->
free(alloc->
userdata, context);
12176 spc->pixels = pixels;
12177 spc->pack_info = context;
12178 spc->nodes = nodes;
12179 spc->padding = padding;
12180 spc->stride_in_bytes = (stride_in_bytes != 0) ? stride_in_bytes : pw;
12181 spc->h_oversample = 1;
12182 spc->v_oversample = 1;
12184 nk_rp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
12186 NK_MEMSET(pixels, 0, (
nk_size)(pw*ph));
12190 nk_tt_PackEnd(
struct nk_tt_pack_context *spc,
struct nk_allocator *alloc)
12196 nk_tt_PackSetOversampling(
struct nk_tt_pack_context *spc,
12197 unsigned int h_oversample,
unsigned int v_oversample)
12199 NK_ASSERT(h_oversample <= NK_TT_MAX_OVERSAMPLE);
12200 NK_ASSERT(v_oversample <= NK_TT_MAX_OVERSAMPLE);
12201 if (h_oversample <= NK_TT_MAX_OVERSAMPLE)
12202 spc->h_oversample = h_oversample;
12203 if (v_oversample <= NK_TT_MAX_OVERSAMPLE)
12204 spc->v_oversample = v_oversample;
12207 nk_tt__h_prefilter(
unsigned char *pixels,
int w,
int h,
int stride_in_bytes,
12210 unsigned char buffer[NK_TT_MAX_OVERSAMPLE];
12211 int safe_w = w - kernel_width;
12214 for (j=0; j < h; ++j)
12217 unsigned int total;
12218 NK_MEMSET(buffer, 0, (
nk_size)kernel_width);
12223 switch (kernel_width) {
12225 for (i=0; i <= safe_w; ++i) {
12226 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12227 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12228 pixels[i] = (
unsigned char) (total / 2);
12232 for (i=0; i <= safe_w; ++i) {
12233 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12234 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12235 pixels[i] = (
unsigned char) (total / 3);
12239 for (i=0; i <= safe_w; ++i) {
12240 total += (
unsigned int)pixels[i] - buffer[i & NK_TT__OVER_MASK];
12241 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12242 pixels[i] = (
unsigned char) (total / 4);
12246 for (i=0; i <= safe_w; ++i) {
12247 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12248 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12249 pixels[i] = (
unsigned char) (total / 5);
12253 for (i=0; i <= safe_w; ++i) {
12254 total += (
unsigned int)(pixels[i] - buffer[i & NK_TT__OVER_MASK]);
12255 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i];
12256 pixels[i] = (
unsigned char) (total / (
unsigned int)kernel_width);
12261 for (; i < w; ++i) {
12262 NK_ASSERT(pixels[i] == 0);
12263 total -= (
unsigned int)(buffer[i & NK_TT__OVER_MASK]);
12264 pixels[i] = (
unsigned char) (total / (
unsigned int)kernel_width);
12266 pixels += stride_in_bytes;
12270 nk_tt__v_prefilter(
unsigned char *pixels,
int w,
int h,
int stride_in_bytes,
12273 unsigned char buffer[NK_TT_MAX_OVERSAMPLE];
12274 int safe_h = h - kernel_width;
12277 for (j=0; j < w; ++j)
12280 unsigned int total;
12281 NK_MEMSET(buffer, 0, (
nk_size)kernel_width);
12286 switch (kernel_width) {
12288 for (i=0; i <= safe_h; ++i) {
12289 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12290 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12291 pixels[i*stride_in_bytes] = (
unsigned char) (total / 2);
12295 for (i=0; i <= safe_h; ++i) {
12296 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12297 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12298 pixels[i*stride_in_bytes] = (
unsigned char) (total / 3);
12302 for (i=0; i <= safe_h; ++i) {
12303 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12304 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12305 pixels[i*stride_in_bytes] = (
unsigned char) (total / 4);
12309 for (i=0; i <= safe_h; ++i) {
12310 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12311 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12312 pixels[i*stride_in_bytes] = (
unsigned char) (total / 5);
12316 for (i=0; i <= safe_h; ++i) {
12317 total += (
unsigned int)(pixels[i*stride_in_bytes] - buffer[i & NK_TT__OVER_MASK]);
12318 buffer[(i+kernel_width) & NK_TT__OVER_MASK] = pixels[i*stride_in_bytes];
12319 pixels[i*stride_in_bytes] = (
unsigned char) (total / (
unsigned int)kernel_width);
12324 for (; i < h; ++i) {
12325 NK_ASSERT(pixels[i*stride_in_bytes] == 0);
12326 total -= (
unsigned int)(buffer[i & NK_TT__OVER_MASK]);
12327 pixels[i*stride_in_bytes] = (
unsigned char) (total / (
unsigned int)kernel_width);
12333 nk_tt__oversample_shift(
int oversample)
12342 return (
float)-(oversample - 1) / (2.0f * (
float)oversample);
12345 nk_tt_PackFontRangesGatherRects(
struct nk_tt_pack_context *spc,
12346 struct nk_tt_fontinfo *info,
struct nk_tt_pack_range *ranges,
12347 int num_ranges,
struct nk_rp_rect *rects)
12353 for (i=0; i < num_ranges; ++i) {
12354 float fh = ranges[i].font_size;
12355 float scale = (fh > 0) ? nk_tt_ScaleForPixelHeight(info, fh):
12356 nk_tt_ScaleForMappingEmToPixels(info, -fh);
12357 ranges[i].h_oversample = (
unsigned char) spc->h_oversample;
12358 ranges[i].v_oversample = (
unsigned char) spc->v_oversample;
12359 for (j=0; j < ranges[i].num_chars; ++j) {
12361 int codepoint = ranges[i].first_unicode_codepoint_in_range ?
12362 ranges[i].first_unicode_codepoint_in_range + j :
12363 ranges[i].array_of_unicode_codepoints[j];
12365 int glyph = nk_tt_FindGlyphIndex(info, codepoint);
12366 nk_tt_GetGlyphBitmapBoxSubpixel(info,glyph, scale * (
float)spc->h_oversample,
12367 scale * (
float)spc->v_oversample, 0,0, &x0,&y0,&x1,&y1);
12368 rects[k].w = (nk_rp_coord) (x1-x0 + spc->padding + (
int)spc->h_oversample-1);
12369 rects[k].h = (nk_rp_coord) (y1-y0 + spc->padding + (
int)spc->v_oversample-1);
12376 nk_tt_PackFontRangesRenderIntoRects(
struct nk_tt_pack_context *spc,
12377 struct nk_tt_fontinfo *info,
struct nk_tt_pack_range *ranges,
12378 int num_ranges,
struct nk_rp_rect *rects,
struct nk_allocator *alloc)
12380 int i,j,k, return_value = 1;
12382 int old_h_over = (int)spc->h_oversample;
12383 int old_v_over = (
int)spc->v_oversample;
12387 for (i=0; i < num_ranges; ++i)
12389 float fh = ranges[i].font_size;
12390 float recip_h,recip_v,sub_x,sub_y;
12391 float scale = fh > 0 ? nk_tt_ScaleForPixelHeight(info, fh):
12392 nk_tt_ScaleForMappingEmToPixels(info, -fh);
12394 spc->h_oversample = ranges[i].h_oversample;
12395 spc->v_oversample = ranges[i].v_oversample;
12397 recip_h = 1.0f / (float)spc->h_oversample;
12398 recip_v = 1.0f / (
float)spc->v_oversample;
12400 sub_x = nk_tt__oversample_shift((
int)spc->h_oversample);
12401 sub_y = nk_tt__oversample_shift((
int)spc->v_oversample);
12403 for (j=0; j < ranges[i].num_chars; ++j)
12405 struct nk_rp_rect *r = &rects[k];
12408 struct nk_tt_packedchar *bc = &ranges[i].chardata_for_range[j];
12409 int advance, lsb, x0,y0,x1,y1;
12410 int codepoint = ranges[i].first_unicode_codepoint_in_range ?
12411 ranges[i].first_unicode_codepoint_in_range + j :
12412 ranges[i].array_of_unicode_codepoints[j];
12413 int glyph = nk_tt_FindGlyphIndex(info, codepoint);
12414 nk_rp_coord pad = (nk_rp_coord) spc->padding;
12417 r->x = (nk_rp_coord)((int)r->x + (
int)pad);
12418 r->y = (nk_rp_coord)((
int)r->y + (int)pad);
12419 r->w = (nk_rp_coord)((
int)r->w - (int)pad);
12420 r->h = (nk_rp_coord)((
int)r->h - (int)pad);
12422 nk_tt_GetGlyphHMetrics(info, glyph, &advance, &lsb);
12423 nk_tt_GetGlyphBitmapBox(info, glyph, scale * (
float)spc->h_oversample,
12424 (scale * (
float)spc->v_oversample), &x0,&y0,&x1,&y1);
12425 nk_tt_MakeGlyphBitmapSubpixel(info, spc->pixels + r->x + r->y*spc->stride_in_bytes,
12426 (
int)(r->w - spc->h_oversample+1), (
int)(r->h - spc->v_oversample+1),
12427 spc->stride_in_bytes, scale * (
float)spc->h_oversample,
12428 scale * (
float)spc->v_oversample, 0,0, glyph, alloc);
12430 if (spc->h_oversample > 1)
12431 nk_tt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
12432 r->w, r->h, spc->stride_in_bytes, (
int)spc->h_oversample);
12434 if (spc->v_oversample > 1)
12435 nk_tt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
12436 r->w, r->h, spc->stride_in_bytes, (
int)spc->v_oversample);
12442 bc->xadvance = scale * (float)advance;
12443 bc->xoff = (float) x0 * recip_h + sub_x;
12444 bc->yoff = (float) y0 * recip_v + sub_y;
12445 bc->xoff2 = ((float)x0 + r->w) * recip_h + sub_x;
12446 bc->yoff2 = ((float)y0 + r->h) * recip_v + sub_y;
12454 spc->h_oversample = (
unsigned int)old_h_over;
12455 spc->v_oversample = (
unsigned int)old_v_over;
12456 return return_value;
12459 nk_tt_GetPackedQuad(
struct nk_tt_packedchar *chardata,
int pw,
int ph,
12460 int char_index,
float *xpos,
float *ypos,
struct nk_tt_aligned_quad *q,
12461 int align_to_integer)
12463 float ipw = 1.0f / (float)pw, iph = 1.0f / (
float)ph;
12464 struct nk_tt_packedchar *b = (
struct nk_tt_packedchar*)(chardata + char_index);
12465 if (align_to_integer) {
12466 int tx = nk_ifloorf((*xpos + b->xoff) + 0.5f);
12467 int ty = nk_ifloorf((*ypos + b->yoff) + 0.5f);
12469 float x = (float)tx;
12470 float y = (float)ty;
12474 q->x1 = x + b->xoff2 - b->xoff;
12475 q->y1 = y + b->yoff2 - b->yoff;
12477 q->x0 = *xpos + b->xoff;
12478 q->y0 = *ypos + b->yoff;
12479 q->x1 = *xpos + b->xoff2;
12480 q->y1 = *ypos + b->yoff2;
12482 q->s0 = b->x0 * ipw;
12483 q->t0 = b->y0 * iph;
12484 q->s1 = b->x1 * ipw;
12485 q->t1 = b->y1 * iph;
12486 *xpos += b->xadvance;
12494 struct nk_font_bake_data {
12495 struct nk_tt_fontinfo info;
12496 struct nk_rp_rect *rects;
12497 struct nk_tt_pack_range *ranges;
12501 struct nk_font_baker {
12503 struct nk_tt_pack_context spc;
12504 struct nk_font_bake_data *build;
12505 struct nk_tt_packedchar *packed_chars;
12506 struct nk_rp_rect *rects;
12507 struct nk_tt_pack_range *ranges;
12517 nk_range_count(
const nk_rune *range)
12521 if (!range)
return 0;
12522 while (*(iter++) != 0);
12523 return (iter == range) ? 0 : (int)((iter - range)/2);
12526 nk_range_glyph_count(
const nk_rune *range,
int count)
12529 int total_glyphs = 0;
12530 for (i = 0; i < count; ++i) {
12535 diff = (int)((t - f) + 1);
12536 total_glyphs += diff;
12538 return total_glyphs;
12541 nk_font_default_glyph_ranges(
void)
12547 nk_font_chinese_glyph_ranges(
void)
12560 nk_font_cyrillic_glyph_ranges(
void)
12572 nk_font_korean_glyph_ranges(
void)
12583 nk_font_baker_memory(
nk_size *temp,
int *glyph_count,
12584 struct nk_font_config *config_list,
int count)
12586 int range_count = 0;
12587 int total_range_count = 0;
12588 struct nk_font_config *iter, *i;
12590 NK_ASSERT(config_list);
12591 NK_ASSERT(glyph_count);
12592 if (!config_list) {
12598 for (iter = config_list; iter; iter = iter->next) {
12600 do {
if (!i->range) iter->range = nk_font_default_glyph_ranges();
12601 range_count = nk_range_count(i->range);
12602 total_range_count += range_count;
12603 *glyph_count += nk_range_glyph_count(i->range, range_count);
12604 }
while ((i = i->n) != iter);
12606 *temp = (
nk_size)*glyph_count *
sizeof(
struct nk_rp_rect);
12607 *temp += (
nk_size)total_range_count *
sizeof(
struct nk_tt_pack_range);
12608 *temp += (
nk_size)*glyph_count *
sizeof(
struct nk_tt_packedchar);
12609 *temp += (
nk_size)count *
sizeof(
struct nk_font_bake_data);
12610 *temp +=
sizeof(
struct nk_font_baker);
12611 *temp += nk_rect_align + nk_range_align + nk_char_align;
12612 *temp += nk_build_align + nk_baker_align;
12615 nk_font_baker(
void *memory,
int glyph_count,
int count,
struct nk_allocator *alloc)
12617 struct nk_font_baker *baker;
12618 if (!memory)
return 0;
12620 baker = (
struct nk_font_baker*)
NK_ALIGN_PTR(memory, nk_baker_align);
12621 baker->build = (
struct nk_font_bake_data*)
NK_ALIGN_PTR((baker + 1), nk_build_align);
12622 baker->packed_chars = (
struct nk_tt_packedchar*)
NK_ALIGN_PTR((baker->build + count), nk_char_align);
12623 baker->rects = (
struct nk_rp_rect*)
NK_ALIGN_PTR((baker->packed_chars + glyph_count), nk_rect_align);
12624 baker->ranges = (
struct nk_tt_pack_range*)
NK_ALIGN_PTR((baker->rects + glyph_count), nk_range_align);
12625 baker->alloc = *alloc;
12629 nk_font_bake_pack(
struct nk_font_baker *baker,
12630 nk_size *image_memory,
int *width,
int *height,
struct nk_recti *custom,
12631 const struct nk_font_config *config_list,
int count,
12635 const struct nk_font_config *config_iter, *it;
12636 int total_glyph_count = 0;
12637 int total_range_count = 0;
12638 int range_count = 0;
12641 NK_ASSERT(image_memory);
12644 NK_ASSERT(config_list);
12648 if (!image_memory || !width || !height || !config_list || !count)
return nk_false;
12649 for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
12651 do {range_count = nk_range_count(it->range);
12652 total_range_count += range_count;
12653 total_glyph_count += nk_range_glyph_count(it->range, range_count);
12654 }
while ((it = it->n) != config_iter);
12657 for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
12659 do {
if (!nk_tt_InitFont(&baker->build[i++].info, (
const unsigned char*)it->ttf_blob, 0))
12661 }
while ((it = it->n) != config_iter);
12664 *width = (total_glyph_count > 1000) ? 1024 : 512;
12665 nk_tt_PackBegin(&baker->spc, 0, (
int)*width, (
int)max_height, 0, 1, alloc);
12674 struct nk_rp_rect custom_space;
12675 nk_zero(&custom_space,
sizeof(custom_space));
12676 custom_space.w = (nk_rp_coord)(custom->
w);
12677 custom_space.h = (nk_rp_coord)(custom->
h);
12679 nk_tt_PackSetOversampling(&baker->spc, 1, 1);
12680 nk_rp_pack_rects((
struct nk_rp_context*)baker->spc.pack_info, &custom_space, 1);
12681 *height =
NK_MAX(*height, (
int)(custom_space.y + custom_space.h));
12683 custom->
x = (short)custom_space.x;
12684 custom->
y = (
short)custom_space.y;
12685 custom->
w = (short)custom_space.w;
12686 custom->
h = (
short)custom_space.h;
12690 for (input_i = 0, config_iter = config_list; input_i < count && config_iter;
12691 config_iter = config_iter->next) {
12696 const struct nk_font_config *cfg = it;
12697 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12700 glyph_count = 0; range_count = 0;
12701 for (in_range = cfg->range; in_range[0] && in_range[1]; in_range += 2) {
12702 glyph_count += (int)(in_range[1] - in_range[0]) + 1;
12707 tmp->ranges = baker->ranges + range_n;
12708 tmp->range_count = (
nk_rune)range_count;
12709 range_n += range_count;
12710 for (i = 0; i < range_count; ++i) {
12711 in_range = &cfg->range[i * 2];
12712 tmp->ranges[i].font_size = cfg->size;
12713 tmp->ranges[i].first_unicode_codepoint_in_range = (int)in_range[0];
12714 tmp->ranges[i].num_chars = (int)(in_range[1]- in_range[0]) + 1;
12715 tmp->ranges[i].chardata_for_range = baker->packed_chars + char_n;
12716 char_n += tmp->ranges[i].num_chars;
12720 tmp->rects = baker->rects + rect_n;
12721 rect_n += glyph_count;
12722 nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v);
12723 n = nk_tt_PackFontRangesGatherRects(&baker->spc, &tmp->info,
12724 tmp->ranges, (
int)tmp->range_count, tmp->rects);
12725 nk_rp_pack_rects((
struct nk_rp_context*)baker->spc.pack_info, tmp->rects, (
int)n);
12728 for (i = 0; i < n; ++i) {
12729 if (tmp->rects[i].was_packed)
12730 *height =
NK_MAX(*height, tmp->rects[i].y + tmp->rects[i].h);
12732 }
while ((it = it->n) != config_iter);
12734 NK_ASSERT(rect_n == total_glyph_count);
12735 NK_ASSERT(char_n == total_glyph_count);
12736 NK_ASSERT(range_n == total_range_count);
12738 *height = (int)nk_round_up_pow2((
nk_uint)*height);
12743 nk_font_bake(
struct nk_font_baker *baker,
void *image_memory,
int width,
int height,
12744 struct nk_font_glyph *glyphs,
int glyphs_count,
12745 const struct nk_font_config *config_list,
int font_count)
12749 const struct nk_font_config *config_iter;
12750 const struct nk_font_config *it;
12752 NK_ASSERT(image_memory);
12755 NK_ASSERT(config_list);
12757 NK_ASSERT(font_count);
12758 NK_ASSERT(glyphs_count);
12759 if (!image_memory || !width || !height || !config_list ||
12760 !font_count || !glyphs || !glyphs_count)
12765 baker->spc.pixels = (
unsigned char*)image_memory;
12766 baker->spc.height = (int)height;
12767 for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter;
12768 config_iter = config_iter->next) {
12770 do {
const struct nk_font_config *cfg = it;
12771 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12772 nk_tt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v);
12773 nk_tt_PackFontRangesRenderIntoRects(&baker->spc, &tmp->info, tmp->ranges,
12774 (
int)tmp->range_count, tmp->rects, &baker->alloc);
12775 }
while ((it = it->n) != config_iter);
12776 } nk_tt_PackEnd(&baker->spc, &baker->alloc);
12779 for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter;
12780 config_iter = config_iter->next) {
12785 const struct nk_font_config *cfg = it;
12786 struct nk_font_bake_data *tmp = &baker->build[input_i++];
12787 struct nk_baked_font *dst_font = cfg->font;
12789 float font_scale = nk_tt_ScaleForPixelHeight(&tmp->info, cfg->size);
12790 int unscaled_ascent, unscaled_descent, unscaled_line_gap;
12791 nk_tt_GetFontVMetrics(&tmp->info, &unscaled_ascent, &unscaled_descent,
12792 &unscaled_line_gap);
12795 if (!cfg->merge_mode) {
12796 dst_font->ranges = cfg->range;
12797 dst_font->height = cfg->size;
12798 dst_font->ascent = ((float)unscaled_ascent * font_scale);
12799 dst_font->descent = ((float)unscaled_descent * font_scale);
12800 dst_font->glyph_offset = glyph_n;
12804 for (i = 0; i < tmp->range_count; ++i) {
12805 struct nk_tt_pack_range *range = &tmp->ranges[i];
12806 for (char_idx = 0; char_idx < range->num_chars; char_idx++)
12809 float dummy_x = 0, dummy_y = 0;
12810 struct nk_tt_aligned_quad q;
12811 struct nk_font_glyph *glyph;
12814 const struct nk_tt_packedchar *pc = &range->chardata_for_range[char_idx];
12815 if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1)
continue;
12816 codepoint = (
nk_rune)(range->first_unicode_codepoint_in_range + char_idx);
12817 nk_tt_GetPackedQuad(range->chardata_for_range, (
int)width,
12818 (
int)height, char_idx, &dummy_x, &dummy_y, &q, 0);
12821 glyph = &glyphs[dst_font->glyph_offset + dst_font->glyph_count + (
unsigned int)glyph_count];
12822 glyph->codepoint = codepoint;
12823 glyph->x0 = q.x0; glyph->y0 = q.y0;
12824 glyph->x1 = q.x1; glyph->y1 = q.y1;
12825 glyph->y0 += (dst_font->ascent + 0.5f);
12826 glyph->y1 += (dst_font->ascent + 0.5f);
12827 glyph->w = glyph->x1 - glyph->x0 + 0.5f;
12828 glyph->h = glyph->y1 - glyph->y0;
12830 if (cfg->coord_type == NK_COORD_PIXEL) {
12831 glyph->u0 = q.s0 * (float)width;
12832 glyph->v0 = q.t0 * (float)height;
12833 glyph->u1 = q.s1 * (float)width;
12834 glyph->v1 = q.t1 * (float)height;
12841 glyph->xadvance = (pc->xadvance + cfg->spacing.x);
12842 if (cfg->pixel_snap)
12843 glyph->xadvance = (float)(
int)(glyph->xadvance + 0.5f);
12847 dst_font->glyph_count += glyph_count;
12848 glyph_n += glyph_count;
12849 }
while ((it = it->n) != config_iter);
12853 nk_font_bake_custom_data(
void *img_memory,
int img_width,
int img_height,
12854 struct nk_recti img_dst,
const char *texture_data_mask,
int tex_width,
12855 int tex_height,
char white,
char black)
12862 NK_ASSERT(img_memory);
12863 NK_ASSERT(img_width);
12864 NK_ASSERT(img_height);
12865 NK_ASSERT(texture_data_mask);
12867 if (!img_memory || !img_width || !img_height || !texture_data_mask)
12870 pixels = (
nk_byte*)img_memory;
12871 for (y = 0, n = 0; y < tex_height; ++y) {
12872 for (x = 0; x < tex_width; ++x, ++n) {
12873 const int off0 = ((img_dst.
x + x) + (img_dst.
y + y) * img_width);
12874 const int off1 = off0 + 1 + tex_width;
12875 pixels[off0] = (texture_data_mask[n] == white) ? 0xFF : 0x00;
12876 pixels[off1] = (texture_data_mask[n] == black) ? 0xFF : 0x00;
12881 nk_font_bake_convert(
void *out_memory,
int img_width,
int img_height,
12882 const void *in_memory)
12888 NK_ASSERT(out_memory);
12889 NK_ASSERT(in_memory);
12890 NK_ASSERT(img_width);
12891 NK_ASSERT(img_height);
12892 if (!out_memory || !in_memory || !img_height || !img_width)
return;
12895 src = (
const nk_byte*)in_memory;
12896 for (n = (
int)(img_width * img_height); n > 0; n--)
12897 *dst++ = ((
nk_rune)(*src++) << 24) | 0x00FFFFFF;
12906 nk_font_text_width(
nk_handle handle,
float height,
const char *text,
int len)
12910 float text_width = 0;
12914 struct nk_font *font = (
struct nk_font*)handle.
ptr;
12916 NK_ASSERT(font->glyphs);
12917 if (!font || !text || !len)
12920 scale = height/font->info.height;
12921 glyph_len = text_len =
nk_utf_decode(text, &unicode, (
int)len);
12922 if (!glyph_len)
return 0;
12923 while (text_len <= (
int)len && glyph_len) {
12924 const struct nk_font_glyph *g;
12928 g = nk_font_find_glyph(font, unicode);
12929 text_width += g->xadvance * scale;
12932 glyph_len =
nk_utf_decode(text + text_len, &unicode, (
int)len - text_len);
12933 text_len += glyph_len;
12937 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 12939 nk_font_query_font_glyph(
nk_handle handle,
float height,
12940 struct nk_user_font_glyph *glyph,
nk_rune codepoint,
nk_rune next_codepoint)
12943 const struct nk_font_glyph *g;
12944 struct nk_font *font;
12949 font = (
struct nk_font*)handle.
ptr;
12951 NK_ASSERT(font->glyphs);
12952 if (!font || !glyph)
12955 scale = height/font->info.height;
12956 g = nk_font_find_glyph(font, codepoint);
12957 glyph->width = (g->x1 - g->x0) * scale;
12958 glyph->height = (g->y1 - g->y0) * scale;
12959 glyph->offset =
nk_vec2(g->x0 * scale, g->y0 * scale);
12960 glyph->xadvance = (g->xadvance * scale);
12961 glyph->uv[0] =
nk_vec2(g->u0, g->v0);
12962 glyph->uv[1] =
nk_vec2(g->u1, g->v1);
12965 NK_API const struct nk_font_glyph*
12966 nk_font_find_glyph(
struct nk_font *font,
nk_rune unicode)
12970 int total_glyphs = 0;
12971 const struct nk_font_glyph *glyph = 0;
12972 const struct nk_font_config *iter = 0;
12975 NK_ASSERT(font->glyphs);
12976 NK_ASSERT(font->info.ranges);
12977 if (!font || !font->glyphs)
return 0;
12979 glyph = font->fallback;
12980 iter = font->config;
12981 do {count = nk_range_count(iter->range);
12982 for (i = 0; i < count; ++i) {
12983 nk_rune f = iter->range[(i*2)+0];
12984 nk_rune t = iter->range[(i*2)+1];
12985 int diff = (int)((t - f) + 1);
12986 if (unicode >= f && unicode <= t)
12987 return &font->glyphs[((
nk_rune)total_glyphs + (unicode - f))];
12988 total_glyphs += diff;
12990 }
while ((iter = iter->n) != font->config);
12994 nk_font_init(
struct nk_font *font,
float pixel_height,
12995 nk_rune fallback_codepoint,
struct nk_font_glyph *glyphs,
12996 const struct nk_baked_font *baked_font,
nk_handle atlas)
12998 struct nk_baked_font baked;
13001 NK_ASSERT(baked_font);
13002 if (!font || !glyphs || !baked_font)
13005 baked = *baked_font;
13006 font->fallback = 0;
13007 font->info = baked;
13008 font->scale = (float)pixel_height / (
float)font->info.height;
13009 font->glyphs = &glyphs[baked_font->glyph_offset];
13010 font->texture = atlas;
13011 font->fallback_codepoint = fallback_codepoint;
13012 font->fallback = nk_font_find_glyph(font, fallback_codepoint);
13014 font->handle.height = font->info.height * font->scale;
13015 font->handle.width = nk_font_text_width;
13016 font->handle.userdata.ptr = font;
13017 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 13018 font->handle.query = nk_font_query_font_glyph;
13019 font->handle.texture = font->texture;
13032 #ifdef NK_INCLUDE_DEFAULT_FONT 13035 #pragma clang diagnostic push 13037 #pragma clang diagnostic ignored "-Woverlength-strings" 13038 #elif defined(__GNUC__) || defined(__GNUG__) 13039 #pragma GCC diagnostic push 13040 #pragma GCC diagnostic ignored "-Woverlength-strings" 13043 NK_GLOBAL const char nk_proggy_clean_ttf_compressed_data_base85[11980+1] =
13044 "7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/" 13045 "2*>]b(MC;$jPfY.;h^`IWM9<Lh2TlS+f-s$o6Q<BWH`YiU.xfLq$N;$0iR/GX:U(jcW2p/W*q?-qmnUCI;jHSAiFWM.R*kU@C=GH?a9wp8f$e.-4^Qg1)Q-GL(lf(r/7GrRgwV%MS=C#" 13046 "`8ND>Qo#t'X#(v#Y9w0#1D$CIf;W'#pWUPXOuxXuU(H9M(1<q-UE31#^-V'8IRUo7Qf./L>=Ke$$'5F%)]0^#0X@U.a<r:QLtFsLcL6##lOj)#.Y5<-R&KgLwqJfLgN&;Q?gI^#DY2uL" 13047 "i@^rMl9t=cWq6##weg>$FBjVQTSDgEKnIS7EM9>ZY9w0#L;>>#Mx&4Mvt//L[MkA#W@lK.N'[0#7RL_&#w+F%HtG9M#XL`N&.,GM4Pg;-<nLENhvx>-VsM.M0rJfLH2eTM`*oJMHRC`N" 13048 "kfimM2J,W-jXS:)r0wK#@Fge$U>`w'N7G#$#fB#$E^$#:9:hk+eOe--6x)F7*E%?76%^GMHePW-Z5l'&GiF#$956:rS?dA#fiK:)Yr+`�j@'DbG&#^$PG.Ll+DNa<XCMKEV*N)LN/N" 13049 "*b=%Q6pia-Xg8I$<MR&,VdJe$<(7G;Ckl'&hF;;$<_=X(b.RS%%)###MPBuuE1V:v&cXm#(&cV]`k9OhLMbn%s$G2,B$BfD3X*sp5#l,$R#]x_X1xKX%b5U*[r5iMfUo9U`N99hG)" 13050 "tm+/Us9pG)XPu`<0s-)WTt(gCRxIg(%6sfh=ktMKn3j)<6<b5Sk_/0(^]AaN#(p/L>&VZ>1i%h1S9u5o@YaaW$e+b<TWFn/Z:Oh(Cx2$lNEoN^e)#CFY@@I;BOQ*sRwZtZxRcU7uW6CX" 13051 "ow0i(?$Q[cjOd[P4d)]>ROPOpxTO7Stwi1::iB1q)C_=dV26J;2,]7op$]uQr@_V7$q^%lQwtuHY]=DX,n3L#0PHDO4f9>dC@O>HBuKPpP*E,N+b3L#lpR/MrTEH.IAQk.a>D[.e;mc." 13052 "x]Ip.PH^'/aqUO/$1WxLoW0[iLA<QT;5HKD+@qQ'NQ(3_PLhE48R.qAPSwQ0/WK?Z,[x?-J;jQTWA0X@KJ(_Y8N-:/M74:/-ZpKrUss?d#dZq]DAbkU*JqkL+nwX@@47`5>w=4h(9.`G" 13053 "CRUxHPeR`5Mjol(dUWxZa(>STrPkrJiWx`5U7F#.g*jrohGg`cg:lSTvEY/EV_7H4Q9[Z%cnv;JQYZ5q.l7Zeas:HOIZOB?G<Nald$qs]@]L<J7bR*>gv:[7MI2k).'2($5FNP&EQ(,)" 13054 "U]W]+fh18.vsai00);D3@4ku5P?DP8aJt+;qUM]=+b'8@;mViBKx0DE[-auGl8:PJ&Dj+M6OC]O^((##]`0i)drT;-7X`=-H3[igUnPG-NZlo.#k@h#=Ork$m>a>$-?Tm$UV(?#P6YY#" 13055 "'/###xe7q.73rI3*pP/$1>s9)W,JrM7SN]'/4C#v$U`0#V.[0>xQsH$fEmPMgY2u7Kh(G%siIfLSoS+MK2eTM$=5,M8p`A.;_R%#u[K#$x4AG8.kK/HSB==-'Ie/QTtG?-.*^N-4B/ZM" 13056 "_3YlQC7(p7q)&](`6_c)$/*JL(L-^(]$wIM`dPtOdGA,U3:w2M-0<q-]L_?^)1vw'.,MRsqVr.L;aN&#/EgJ)PBc[-f>+WomX2u7lqM2iEumMTcsF?-aT=Z-97UEnXglEn1K-bnEO`gu" 13057 "Ft(c%=;Am_Qs@jLooI&NX;]0#j4#F14;gl8-GQpgwhrq8'=l_f-b49'UOqkLu7-##oDY2L(te+Mch&gLYtJ,MEtJfLh'x'M=$CS-ZZ%P]8bZ>#S?YY#%Q&q'3^Fw&?D)UDNrocM3A76/" 13058 "/oL?#h7gl85[qW/NDOk%16ij;+:1a'iNIdb-ou8.P*w,v5#EI$TWS>Pot-R*H'-SEpA:g)f+O$%%`kA#G=8RMmG1&O`>to8bC]T&$,n.LoO>29sp3dt-52U%VM#q7'DHpg+#Z9%H[K<L" 13059 "%a2E-grWVM3@2=-k22tL]4$##6We'8UJCKE[d_=%wI;'6X-GsLX4j^SgJ$##R*w,vP3wK#iiW&#*h^D&R?jp7+/u&#(AP##XU8c$fSYW-J95_-Dp[g9wcO&#M-h1OcJlc-*vpw0xUX&#" 13060 "OQFKNX@QI'IoPp7nb,QU//MQ&ZDkKP)X<WSVL(68uVl&#c'[0#(s1X&xm$Y%B7*K:eDA323j998GXbA#pwMs-jgD$9QISB-A_(aN4xoFM^@C58D0+Q+q3n0#3U1InDjF682-SjMXJK)(" 13061 "h$hxua_K]ul92%'BOU&#BRRh-slg8KDlr:%L71Ka:.A;%YULjDPmL<LYs8i#XwJOYaKPKc1h:'9Ke,g)b),78=I39B;xiY$bgGw-&.Zi9InXDuYa%G*f2Bq7mn9^#p1vv%#(Wi-;/Z5h" 13062 "o;#2:;%d	v68C5g?ntX0X)pT`;%pB3q7mgGN)3%(P8nTd5L7GeA-GL@+%J3u2:(Yf>et`e;)f#Km8&+DC$I46>#Kr]]u-[=99tts1.qb#q72g1WJO81q+eN'03'eM>&1XxY-caEnO" 13063 "j%2n8)),?ILR5^.Ibn<-X-Mq7[a82Lq:F&#ce+S9wsCK*x`569E8ew'He]h:sI[2LM$[guka3ZRd6:t%IG:;$%YiJ:Nq=?eAw;/:nnDq0(CYcMpG)qLN4$##&J<j$UpK<Q4a1]MupW^-" 13064 "sj_$%[HK%'F####QRZJ::Y3EGl4'@%FkiAOg#p[##O`gukTfBHagL<LHw%q&OV0##F=6/:chIm0@eCP8X]:kFI%hl8hgO@RcBhS-@Qb$%+m=hPDLg*%K8ln(wcf3/'DW-$.lR?n[nCH-" 13065 "eXOONTJlh:.RYF%3'p6sq:UIMA945&^HFS87@$EP2iG<-lCO$%c`uKGD3rC$x0BL8aFn--`ke%#HMP'vh1/R&O_J9'um,.<tx[@%wsJk&bUT2`0uMv7gg#qp/ij.L56'hl;.s5CUrxjO" 13066 "M7-##.l+Au'A&O:-T72L]P`&=;ctp'XScX*rU.>-XTt,%OVU4)S1+R-#dg0/Nn?Ku1^0f$B*P:Rowwm-`0PKjYDDM'3]d39VZHEl4,.j']Pk-M.h^&:0FACm$maq-&sgw0t7/6(^xtk%" 13067 "LuH88Fj-ekm>GA#_>568x6(OFRl-IZp`&b,_P'$M<Jnq79VsJW/mWS*PUiq76;]/NM_>hLbxfc$mj`,O;&%W2m`Zh:/)Uetw:aJ%]K9h:TcF]u_-Sj9,VK3M.*'&0D[Ca]J9gp8,kAW]" 13068 "%(?A%R$f<->Zts'^kn=-^@c4%-pY6qI%J%1IGxfLU9CP8cbPlXv);C=b),<2mOvP8up,UVf3839acAWAW-W?#ao/^#%KYo8fRULNd2.>%m]UK:n%r$'sw]J;5pAoO_#2mO3n,'=H5(et" 13069 "Hg*`+RLgv>=4U8guD$I%D:W>-r5V*%j*W:Kvej.Lp$<M-SGZ':+Q_k+uvOSLiEo(<aD/K<CCc`'Lx>'?;++O'>()jLR-^u68PHm8ZFWe+ej8h:9r6L*0//c&iH&R8pRbA#Kjm%upV1g:" 13070 "a_#Ur7FuA#(tRh#.Y5K+@?3<-8m0$PEn;J:rh6?I6uG<-`wMU'ircp0LaE_OtlMb&1#6T.#FDKu#1Lw%u%+GM+X'e?YLfjM[VO0MbuFp7;>Q&#WIo)0@F%q7c#4XAXN-U&VB<HFF*qL(" 13071 "$/V,;(kXZejWO`<[5?\?ewY(*9=%wDc;,u<'9t3W-(H1th3+G]ucQ]kLs7df($/*JL]@*t7Bu_G3_7mp7<iaQjO@.kLg;x3B0lqp7Hf,^Ze7-##@/c58Mo(3;knp0%)A7?-W+eI'o8)b<" 13072 "nKnw'Ho8C=Y>pqB>0ie&jhZ[?iLR@@_AvA-iQC(=ksRZRVp7`.=+NpBC%rh&3]R:8XDmE5^V8O(x<<aG/1N$#FX$0V5Y6x'aErI3I$7x%E`v<-BY,)%-?Psf*l?%C3.mM(=/M0:JxG'?" 13073 "7WhH%o'a<-80g0NBxoO(GH<dM]n.+%q@jH?f.UsJ2Ggs&4<-e47&Kl+f//9@`b+?.TeN_&B8Ss?v;^Trk;f#YvJkl&w$]>-+k?'(<S:68tq*WoDfZu';mM?8X[ma8W%*`-=;D.(nc7/;" 13074 ")g:T1=^J$&BRV(-lTmNB6xqB[@0*o.erM*<SWF]u2=st-*(6v>^](H.aREZSi,#1:[IXaZFOm<-ui#qUq2$##Ri;u75OK#(RtaW-K-F`S+cF]uN`-KMQ%rP/Xri.LRcB##=YL3BgM/3M" 13075 "D?@f&1'BW-)Ju<L25gl8uhVm1hL$##*8###'A3/LkKW+(^rWX?5W_8g)a(m&K8P>#bmmWCMkk&#TR`C,5d>g)F;t,4:@_l8G/5h4vUd%&%950:VXD'QdWoY-F$BtUwmfe$YqL'8(PWX(" 13076 "P?^@Po3$##`MSs?DWBZ/S>+4%>fX,VWv/w'KD`LP5IbH;rTV>n3cEK8U#bX]l-/V+^lj3;vlMb&[5YQ8#pekX9JP3XUC72L,,?+Ni&co7ApnO*5NK,((W-i:$,kp'UDAO(G0Sq7MVjJs" 13077 "bIu)'Z,*[>br5fX^:FPAWr-m2KgL<LUN098kTF&#lvo58=/vjDo;.;)Ka*hLR#/k=rKbxuV`>Q_nN6'8uTGT5g)uLv:873UpTLgH+#FgpH'_o1780Ph8KmxQJ8#H72L4@768@Tm&Q" 13078 "h4CB/5OvmA&,Q&QbUoi$a_%3M01H)4x7I^&KQVgtFnV+;[Pc>[m4k//,]1?#`VY[Jr*3&&slRfLiVZJ:]?=K3Sw=[$=uRB?3xk48@aeg<Z'<$#4H)6,>e0jT6'N#(q%.O=?2S]u*(m<-" 13079 "V8J'(1)G][68hW$5'q[GC&5j`TE?m'esFGNRM)j,ffZ?-qx8;->g4t*:CIP/[Qap7/9'#(1sao7w-.qNUdkJ)tCF&#B^;xGvn2r9FEPFFFcL@.iFNkTve$m%#QvQS8U@)2Z+3K:AKM5i" 13080 "sZ88+dKQ)W6>J%CL<KE>`.d*(B`-n8D9oK<Up]c$X$(,)M8Zt7/[rdkqTgl-0cuGMv'?>-XV1q['-5k'cAZ69e;D_?$ZPP&s^+7])$*$#@QYi9,5P	r+$%CE=68>K8r0=dSC%%(@p7" 13081 ".m7jilQ02'0-VWAg<a/''3u.=4L$Y)6k/K:_[3=&jvL<L0C/2'v:^;-DIBW,B4E68:kZ;%?8(Q8BH=kO65BW?xSG&#@uU,DS*,?.+(o(#1vCS8#CHF>TlGW'b)Tq7VT9q^*^$$.:&N@@" 13082 "$&)WHtPm*5_rO0&e%K&#-30j(E4#'Zb.o/(Tpm$>K'f@[PvFl,hfINTNU6u'0pao7%XUp9]5.>%h`8_=VYbxuel.NTSsJfLacFu3B'lQSu/m6-Oqem8T+oE--$0a/k]uj9EwsG>%veR*" 13083 "hv^BFpQj:K'#SJ,sB-'#](j.Lg92rTw-*n%@/;39rrJF,l#qV%OrtBeC6/,;qB3ebNW[?,Hqj2L.1NP&GjUR=1D8QaS3Up&@*9wP?+lo7b?@%'k4`p0Z$22%K3+iCZj?XJN4Nm&+YF]u" 13084 "@-W$U%VEQ/,,>>#)D<h#`)h0:<Q6909ua+&VU%n2:cG3FJ-%@Bj-DgLr`Hw&HAKjKjseK</xKT*)B,N9X3]krc12t'pgTV(Lv-tL[xg_%=M_q7a^x?7Ubd>#%8cY#YZ?=,`Wdxu/ae&#" 13085 "w6)R89tI#6@s'(6Bf7a&?S=^ZI_kS&ai`&=tE72L_D,;^R)7[$s<Eh#c&)q.MXI%#v9ROa5FZO%sF7q7Nwb&#ptUJ:aqJe$Sl68%.D###EC><?-aF&#RNQv>o8lKN%5/$(vdfq7+ebA#" 13086 "u1p]ovUKW&Y%q]'>$1@-[xfn$7ZTp7mM,G,Ko7a&Gu%G[RMxJs[0MM%wci.LFDK)(<c`Q8N)jEIF*+?P2a8g%)$q]o2aH8C&<SibC/q,(e:v;-b#6[$NtDZ84Je2KNvB#$P5?tQ3nt(0" 13087 "d=j.LQf./Ll33+(;q3L-w=8dX$#WF&uIJ@-bfI>%:_i2B5CsR8&9Z&#=mPEnm0f`<&c)QL5uJ#%u%lJj+D-r;BoFDoS97h5g)E#o:&S4weDF,9^Hoe`h*L+_a*NrLW-1pG_&2UdB8" 13088 "6e%B/:=>)N4xeW.*wft-;$'58-ESqr<b?UI(_%@[P46>#U`'6AQ]m&6/`Z>#S?YY#Vc;r7U2&326d=w&H####?TZ`*4?&.MK?LP8Vxg>$[QXc%QJv92.(Db*B)gb*BM9dM*hJMAo*c&#" 13089 "b0v=Pjer]$gG&JXDf->'StvU7505l9$AFvgYRI^&<^b68?j#q9QX4SM'RO#&sL1IM.rJfLUAj221]d##DW=m83u5;'bYx,*Sl0hL(W;;$doB&O/TQ:(Z^xBdLjL<Lni;''X.`$#8+1GD" 13090 ":k$YUWsbn8ogh6rxZ2Z9]%nd+>V#*8U_72Lh+2Q8Cj0i:6hp&$C/:p(HK>T8Y[gHQ4`4)'$Ab(Nof%V'8hL&#<NEdtg(n'=S1A(Q1/I&4([%dM`,Iu'1:_hL>SfD07&6D<fp8dHM7/g+" 13091 "tlPN9J*rKaPct&?'uBCem^jn%9_K)<,C5K3s=5g&GmJb*[SYq7K;TRLGCsM-$$;S%:Y@r7AK0pprpL<Lrh,q7e/%KWK:50I^+m'vi`3?%Zp+<-d+$L-Sv:@.o19n$s0&39;kn;S%BSq*" 13092 "$3WoJSCLweV[aZ'MQIjO<7;X-X;&+dMLvu#^UsGEC9WEc[X(wI7#2.(F0jV*eZf<-Qv3J-c+J5AlrB#$p(H68LvEA'q3n0#m,[`*8Ft)FcYgEud]CWfm68,(aLA$@EFTgLXoBq/UPlp7" 13093 ":d[/;r_ix=:TF`S5H-b<LI&HY(K=h#)]Lk$K14lVfm:x$H<3^Ql<M`$OhapBnkup'D#L$Pb_`N*g]2e;X/Dtg,bsj&K#2[-:iYr'_wgH)NUIR8a1n#S?Yej'h8^58UbZd+^FKD*T@;6A" 13094 "7aQC[K8d-(v6GI$x:T<&'Gp5Uf>@M.*J:;$-rv29'M]8qMv-tLp,'886iaC=Hb*YJoKJ,(j%K=H`K.v9HggqBIiZu'QvBT.#=)0ukruV&.)3=(^1`o*Pj4<-<aN((^7('#Z0wK#5GX@7" 13095 "u][`*S^43933A4rl][`*O4CgLEl]v$1Q3AeF37dbXk,.)vj#x'd`;qgbQR%FW,2(?LO=s%Sc68%NP'##Aotl8x=BE#j1UD([3$M(]UI2LX3RpKN@;/#f'f/&_mt&F)XdF<9t4)Qa.*kT" 13096 "LwQ'(TTB9.xH'>#MJ+gLq9-##@HuZPN0]u:h7.T..G:;$/Usj(T7`Q8tT72LnYl<-qx8;-HV7Q-&Xdx%1a,hC=0u+HlsV>nuIQL-5<N?)NBS)QN*_I,?&)2'IM%L3I)X((e/dl2&8'<M" 13097 ":^#M*Q+[T.Xri.LYS3v%fF`68h;b-X[/En'CR.q7E)p'/kle2HM,u;^%OKC-N+Ll%F9CF<Nf'^#t2L,;27W:0O@6##U6W7:$rJfLWHj$#)woqBefIZ.PK<b*t7ed;p*_m;4ExK#h@&]>" 13098 "_>@kXQtMacfD.m-VAb8;IReM3$wf0''hra*so568'Ip&vRs849'MRYSp%:t:h5qSgwpEr$B>Q,;s(C#$)`svQuF$##-D,##,g68@2[T;.XSdN9Qe)rpt._K-#5wF)sP'##p#C0c%-Gb%" 13099 "hd+<-j'Ai*x&&HMkT]C'OSl##5RG[JXaHN;d'uA#x._U;.`PU@(Z3dt4r152@:v,'R.Sj'w#0<-;kPI)FfJ&#AYJ&#//)>-k=m=*XnK$>=)72L]0I%>.G690a:$##<,);?;72#?x9+d;" 13100 "^V'9;jY@;)br#q^YQpx:X#Te$Z^'=-=bGhLf:D6&bNwZ9-ZD#n^9HhLMr5G;']d&6'wYmTFmL<LD)F^%[tC'8;+9E#C$g%#5Y>q9wI>P(9mI[>kC-ekLC/R&CH+s'B;K-M6$EB%is00:" 13101 "+A4[7xks.LrNk0&E)wILYF@2L'0Nb$+pv<(2.768/FrY&h$^3i&@+G%JT'<-,v`3;_)I9M^AE]CN?Cl2AZg+%4iTpT3<n-&%H%b<FDj2M<hH=&Eh<2Len$b*aTX=-8QxN)k11IM1c^j%" 13102 "9s<L<NFSo)B?+<-(GxsF,^-Eh@$4dXhN$+#rxK8'je'D7k`e;)2pYwPA'_p9&@^18ml1^[@g4t*[JOa*[=Qp7(qJ_oOL^('7fB&Hq-:sf,sNj8xq^>$U4O]GKx'm9)b@p7YsvK3w^YR-" 13103 "CdQ*:Ir<($u&)#(&?L9Rg3H)4fiEp^iI9O8KnTj,]H?D*r7'M;PwZ9K0E^k&-cpI;.p/6_vwoFMV<->#%Xi.LxVnrU(4&8/P+:hLSKj$#U%]49t'I:rgMi'FL@a:0Y-uA[39',(vbma*" 13104 "hU%<-SRF`Tt:542R_VV$p@[p8DV[A,?1839FWdF<TddF<9Ah-6&9tWoDlh]&1SpGMq>Ti1O*H&#(AL8[_P%.M>v^-))qOT*F5Cq0`Ye%+$B6i:7@0IX<N+T+0MlMBPQ*Vj>SsD<U4JHY" 13105 "8kD2)2fU/M#$e.)T4,_=8hLim[&);?UkK'-x?'(:siIfL<$pFM`i<?%W(mGDHM%>iWP,##P`%/L<eXi:@Z9C.7o=@(pXdAO/NLQ8lPl+HPOQa8wD8=^GlPa8TKI1CjhsCTSLJM'/Wl>-" 13106 "S(qw%sf/@%#B6;/U7K]uZbi^Oc^2n<bhPmUkMw>%t<)'mEVE''n`WnJra$^TKvX5B>;_aSEK',(hwa0:i4G?.Bci.(X[?b*($,=-n<.Q%`(X=?+@Am*Js0&=3bh8K]mL<LoNs'6,'85`" 13107 "0?t/'_U59@]ddF<#LdF<eWdF<OuN/45rY<-L@&#+fm>69=Lb,OcZV/);TTm8VI;?%OtJ<(b4mq7M6:u?KRdF<gR@2L=FNU-<b[(9c/ML3m;Z[$oF3g)GAWqpARc=<ROu7cL5l;-[A]%/" 13108 "+fsd;l#SafT/f*W]0=O'$(Tb<[)*@e775R-:Yob%g*>l*:xP?Yb.5)%w_I?7uk5JC+FS(m#i'k.'a0i)9<7b'fs'59hq$*5Uhv##pi^8+hIEBF`nvo`;'l0.^S1<-wUK2/Coh58KKhLj" 13109 "M=SO*rfO`+qC`W-On.=AJ56>>i2@2LH6A:&5q`?9I3@@'04&p2/LVa*T-4<-i3;M9UvZd+N7>b*eIwg:CC)c<>nO&#<IGe;__.thjZl<%w(Wk2xmp4Q@I#I9,DF]u7-P=.-_:YJ]aS@V" 13110 "?6*C()dOp7:WL,b&3Rg/.cmM9&r^>$(>.Z-I&J(Q0Hd5Q%7Co-b`-c<N(6r@ip+AurK<m86QIth*#v;-OBqi+L7wDE-Ir8K['m+DDSLwK&/.?-V%U_%3:qKNu$_b*B-kp7NaD'QdWQPK" 13111 "Yq[@>P)hI;*_F]u`Rb[.j8_Q/<&>uu+VsH$sM9TA%?)(vmJ80),P7E>)tjD%2L=-t#fK[%`v=Q8<FfNkgg^oIbah*#8/Qt$F&:K*-(N/'+1vMB,u()-a.VUU*#[e%gAAO(S>WlA2);Sa" 13112 ">gXm8YB`1d@K#n]76-a$U,mF<fX]idqd)<3,]J7JmW4`6]uks=4-72L(jEk+:bJ0M^q-8Dm_Z?0olP1C9Sa&H[d&c$ooQUj]Exd*3ZM@-WGW2%s',B-_M%>%Ul:#/'xoFM9QX-$.QN'>" 13113 "[%$Z$uF6pA6Ki2O5:8w*vP1<-1`[G,)-m#>0`P&#eb#.3i)rtB61(o'$?X3B</R90;eZ]%Ncq;-Tl]#F>2Qft^ae_5tKL9MUe9b*sLEQ95C&`=G?@Mj=wh*'3E>=-<)Gt*Iw)'QG:`@I" 13114 "wOf7&]1i'S01B+Ev/Nac#9S;=;YQpg_6U`*kVY39xK,[/6Aj7:'1Bm-_1EYfa1+o&o4hp7KN_Q(OlIo@S%;jVdn0'1<Vc52=u`3^o-n1'g4v58Hj&6_t7$##?M)c<$bgQ_'SY((-xkA#" 13115 "Y(,p'H9rIVY-b,'%bCPF7.J<Up^,(dU1VY*5#WkTU>h19w,WQhLI)3S#f$2(eb,jr*b;3Vw]*7NH%$c4Vs,eD9>XW8?N]o+(*pgC%/72LV-u<Hp,3@e^9UB1J+ak9-TN/mhKPg+AJYd$" 13116 "MlvAF_jCK*.O-^(63adMT->W%iewS8W6m2rtCpo'RS1R84=@paTKt)>=%&1[)*vp'u+x,VrwN;&]kuO9JDbg=pO$J*.jVe;u'm0dr9l,<*wMK*Oe=g8lV_KEBFkO'oU]^=[-792#ok,)" 13117 "i]lR8qQ2oA8wcRCZ^7w/Njh;?.stX?Q1>S1q4Bn$)K1<-rGdO'$Wr.Lc.CG)$/*JL4tNR/,SVO3,aUw'DJN:)Ss;wGn9A32ijw%FL+Z0Fn.U9;reSq)bmI32U==5ALuG&#Vf1398/pVo" 13118 "1*c-(aY168o<`JsSbk-,1N;$>0:OUas(3:8Z972LSfF8eb=c-;>SPw7.6hn3m`9^Xkn(r.qS[0;T%&Qc=+STRxX'q1BNk3&*eu2;&8q$&x>Q#Q7^Tf+6<(d%ZVmj2bDi%.3L2n+4W'$P" 13119 "iDDG)g,r%+?,$@?uou5tSe2aN_AQU*<h`e-GI7)?OK2A.d7_c)?wQ5AS@DL3r#7fSkgl6-++D:'A,uq7SvlB$pcpH'q3n0#_%dY#xCpr-l<F0NR@-##FEV6NTF6##$l84N1w?AO>'IAO" 13120 "URQ##V^Fv-XFbGM7Fl(N<3DhLGF%q.1rC$#:T__&Pi68%0xi_&[qFJ(77j_&JWoF.V735&T,[R*:xFR*K5>>#`bW-?4Ne_&6Ne_&6Ne_&n`kr-#GJcM6X;uM6X;uM(.a..^2TkL%oR(#" 13121 ";u.T%fAr%4tJ8&><1=GHZ_+m9/#H1F^R#SC#*N=BA9(D?v[UiFY>>^8p,KKF.W]L29uLkLlu/+4T<XoIB&hx=T1PcDaB&;HH+-AFr?(m9HZV)FKS8JCw;SD=6[^/DZUL`EUDf]GGlG&>" 13122 "w$)F./^n3+rlo+DB;5sIYGNk+i1t-69Jg--0pao7Sm#K)pdHW&;LuDNH@H>#/X-TI(;P>#,Gc>#0Su>#4`1?#8lC?#<xU?#@.i?#D:%@#HF7@#LRI@#P_[@#Tkn@#Xw*A#]-=A#a9OA#" 13123 "d<F&#*;G##.GY##2Sl##6`($#:l:$#>xL$#B.`$#F:r$#JF.%#NR@%#R_R%#Vke%#Zww%#_-4^Rh%Sflr-k'MS.o?.5/sWel/wpEM0%3'/1)K^f1-d>G21&v(35>V`39V7A4=onx4" 13124 "A1OY5EI0;6Ibgr6M$HS7Q<)58C5w,;WoA*#[%T*#`1g*#d=#+#hI5+#lUG+#pbY+#tnl+#x$),#&1;,#*=M,#.I`,#2Ur,#6b.-#;w[H#iQtA#m^0B#qjBB#uvTB##-hB#'9$C#+E6C#" 13125 "/QHC#3^ZC#7jmC#;v)D#?,<D#C8ND#GDaD#KPsD#O]/E#g1A5#KA*1#gC17#MGd;#8(02#L-d3#rWM4#Hga1#,<w0#T.j<#O#'2#CYN1#qa^:#_4m3#o@/=#eG8=#t8J5#`+78#4uI-#" 13126 "m3B2#SB[8#Q0@8#i[*9#iOn8#1Nm;#^sN9#qh<9#:=x-#P;K2#$%X9#bC+.#Rg;<#mN=.#MTF.#RZO.#2?)4#Y#(/#[)1/#b;L/#dAU/#0Sv;#lY$0#n`-0#sf60#(F24#wrH0#%/e0#" 13127 "TmD<#%JSMFove:CTBEXI:<eh2g)B,3h2^G3i;#d3jD>)4kMYD4lVu`4m`:&5niUA5@(A5BA1]PBB:xlBCC=2CDLXMCEUtiCf&0g2'tN?PGT4CPGT4CPGT4CPGT4CPGT4CPGT4CPGT4CP" 13128 "GT4CPGT4CPGT4CPGT4CPGT4CPGT4CP-qekC`.9kEg^+F$kwViFJTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5o,^<-28ZI'O?;xp" 13129 "O?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xp;7q-#lLYI:xvD=#";
13132 #define NK_CURSOR_DATA_W 90 13133 #define NK_CURSOR_DATA_H 27 13134 NK_GLOBAL const char nk_custom_cursor_data[NK_CURSOR_DATA_W * NK_CURSOR_DATA_H + 1] =
13136 "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX" 13137 "..- -X.....X- X.X - X.X -X.....X - X.....X" 13138 "--- -XXX.XXX- X...X - X...X -X....X - X....X" 13139 "X - X.X - X.....X - X.....X -X...X - X...X" 13140 "XX - X.X -X.......X- X.......X -X..X.X - X.X..X" 13141 "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X" 13142 "X..X - X.X - X.X - X.X -XX X.X - X.X XX" 13143 "X...X - X.X - X.X - XX X.X XX - X.X - X.X " 13144 "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X " 13145 "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X " 13146 "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X " 13147 "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X " 13148 "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X " 13149 "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X " 13150 "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X " 13151 "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X " 13152 "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX " 13153 "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------" 13154 "X.X X..X - -X.......X- X.......X - XX XX - " 13155 "XX X..X - - X.....X - X.....X - X.X X.X - " 13156 " X..X - X...X - X...X - X..X X..X - " 13157 " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - " 13158 "------------ - X - X -X.....................X- " 13159 " ----------------------------------- X...XXXXXXXXXXXXX...X - " 13166 #pragma clang diagnostic pop 13167 #elif defined(__GNUC__) || defined(__GNUG__) 13168 #pragma GCC diagnostic pop 13178 nk_decompress_length(
unsigned char *input)
13180 return (
unsigned int)((input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]);
13183 nk__match(
unsigned char *data,
unsigned int length)
13186 NK_ASSERT (nk__dout + length <= nk__barrier);
13187 if (nk__dout + length > nk__barrier) { nk__dout += length;
return; }
13188 if (data < nk__barrier4) { nk__dout = nk__barrier+1;
return; }
13189 while (length--) *nk__dout++ = *data++;
13192 nk__lit(
unsigned char *data,
unsigned int length)
13194 NK_ASSERT (nk__dout + length <= nk__barrier);
13195 if (nk__dout + length > nk__barrier) { nk__dout += length;
return; }
13196 if (data < nk__barrier2) { nk__dout = nk__barrier+1;
return; }
13197 NK_MEMCPY(nk__dout, data, length);
13198 nk__dout += length;
13201 nk_decompress_token(
unsigned char *i)
13203 #define nk__in2(x) ((i[x] << 8) + i[(x)+1]) 13204 #define nk__in3(x) ((i[x] << 16) + nk__in2((x)+1)) 13205 #define nk__in4(x) ((i[x] << 24) + nk__in3((x)+1)) 13208 if (*i >= 0x80) nk__match(nk__dout-i[1]-1, (
unsigned int)i[0] - 0x80 + 1), i += 2;
13209 else if (*i >= 0x40) nk__match(nk__dout-(nk__in2(0) - 0x4000 + 1), (
unsigned int)i[2]+1), i += 3;
13210 else nk__lit(i+1, (
unsigned int)i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
13212 if (*i >= 0x18) nk__match(nk__dout-(
unsigned int)(nk__in3(0) - 0x180000 + 1), (
unsigned int)i[3]+1), i += 4;
13213 else if (*i >= 0x10) nk__match(nk__dout-(
unsigned int)(nk__in3(0) - 0x100000 + 1), (
unsigned int)nk__in2(3)+1), i += 5;
13214 else if (*i >= 0x08) nk__lit(i+2, (
unsigned int)nk__in2(0) - 0x0800 + 1), i += 2 + (nk__in2(0) - 0x0800 + 1);
13215 else if (*i == 0x07) nk__lit(i+3, (
unsigned int)nk__in2(1) + 1), i += 3 + (nk__in2(1) + 1);
13216 else if (*i == 0x06) nk__match(nk__dout-(
unsigned int)(nk__in3(1)+1), i[4]+1u), i += 5;
13217 else if (*i == 0x04) nk__match(nk__dout-(
unsigned int)(nk__in3(1)+1), (
unsigned int)nk__in2(4)+1u), i += 6;
13222 nk_adler32(
unsigned int adler32,
unsigned char *buffer,
unsigned int buflen)
13224 const unsigned long ADLER_MOD = 65521;
13225 unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
13226 unsigned long blocklen, i;
13228 blocklen = buflen % 5552;
13230 for (i=0; i + 7 < blocklen; i += 8) {
13231 s1 += buffer[0]; s2 += s1;
13232 s1 += buffer[1]; s2 += s1;
13233 s1 += buffer[2]; s2 += s1;
13234 s1 += buffer[3]; s2 += s1;
13235 s1 += buffer[4]; s2 += s1;
13236 s1 += buffer[5]; s2 += s1;
13237 s1 += buffer[6]; s2 += s1;
13238 s1 += buffer[7]; s2 += s1;
13241 for (; i < blocklen; ++i) {
13242 s1 += *buffer++; s2 += s1;
13245 s1 %= ADLER_MOD; s2 %= ADLER_MOD;
13246 buflen -= (
unsigned int)blocklen;
13249 return (
unsigned int)(s2 << 16) + (
unsigned int)s1;
13252 nk_decompress(
unsigned char *output,
unsigned char *i,
unsigned int length)
13255 if (nk__in4(0) != 0x57bC0000)
return 0;
13256 if (nk__in4(4) != 0)
return 0;
13257 olen = nk_decompress_length(i);
13259 nk__barrier3 = i+length;
13260 nk__barrier = output + olen;
13261 nk__barrier4 = output;
13266 unsigned char *old_i = i;
13267 i = nk_decompress_token(i);
13269 if (*i == 0x05 && i[1] == 0xfa) {
13270 NK_ASSERT(nk__dout == output + olen);
13271 if (nk__dout != output + olen)
return 0;
13272 if (nk_adler32(1, output, olen) != (
unsigned int) nk__in4(2))
13280 NK_ASSERT(nk__dout <= output + olen);
13281 if (nk__dout > output + olen)
13286 nk_decode_85_byte(
char c)
13288 return (
unsigned int)((c >=
'\\') ? c-36 : c-35);
13291 nk_decode_85(
unsigned char* dst,
const unsigned char* src)
13296 nk_decode_85_byte((
char)src[0]) +
13297 85 * (nk_decode_85_byte((
char)src[1]) +
13298 85 * (nk_decode_85_byte((
char)src[2]) +
13299 85 * (nk_decode_85_byte((
char)src[3]) +
13300 85 * nk_decode_85_byte((
char)src[4]))));
13303 dst[0] = (
unsigned char)((tmp >> 0) & 0xFF);
13304 dst[1] = (
unsigned char)((tmp >> 8) & 0xFF);
13305 dst[2] = (
unsigned char)((tmp >> 16) & 0xFF);
13306 dst[3] = (
unsigned char)((tmp >> 24) & 0xFF);
13318 NK_API struct nk_font_config
13319 nk_font_config(float pixel_height)
13321 struct nk_font_config cfg;
13325 cfg.ttf_data_owned_by_atlas = 0;
13326 cfg.size = pixel_height;
13327 cfg.oversample_h = 3;
13328 cfg.oversample_v = 1;
13329 cfg.pixel_snap = 0;
13330 cfg.coord_type = NK_COORD_UV;
13332 cfg.range = nk_font_default_glyph_ranges();
13333 cfg.merge_mode = 0;
13334 cfg.fallback_glyph =
'?';
13339 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 13341 nk_font_atlas_init_default(
struct nk_font_atlas *atlas)
13344 if (!atlas)
return;
13346 atlas->temporary.userdata.ptr = 0;
13347 atlas->temporary.alloc = nk_malloc;
13348 atlas->temporary.free = nk_mfree;
13349 atlas->permanent.userdata.ptr = 0;
13350 atlas->permanent.alloc = nk_malloc;
13351 atlas->permanent.free = nk_mfree;
13355 nk_font_atlas_init(
struct nk_font_atlas *atlas,
struct nk_allocator *alloc)
13359 if (!atlas || !alloc)
return;
13361 atlas->permanent = *alloc;
13362 atlas->temporary = *alloc;
13365 nk_font_atlas_init_custom(
struct nk_font_atlas *atlas,
13369 NK_ASSERT(permanent);
13370 NK_ASSERT(temporary);
13371 if (!atlas || !permanent || !temporary)
return;
13373 atlas->permanent = *permanent;
13374 atlas->temporary = *temporary;
13377 nk_font_atlas_begin(
struct nk_font_atlas *atlas)
13380 NK_ASSERT(atlas->temporary.alloc && atlas->temporary.free);
13381 NK_ASSERT(atlas->permanent.alloc && atlas->permanent.free);
13382 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free ||
13383 !atlas->temporary.alloc || !atlas->temporary.free)
return;
13384 if (atlas->glyphs) {
13385 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13388 if (atlas->pixel) {
13389 atlas->permanent.free(atlas->permanent.userdata, atlas->pixel);
13394 nk_font_atlas_add(
struct nk_font_atlas *atlas,
const struct nk_font_config *config)
13396 struct nk_font *font = 0;
13397 struct nk_font_config *cfg;
13400 NK_ASSERT(atlas->permanent.alloc);
13401 NK_ASSERT(atlas->permanent.free);
13402 NK_ASSERT(atlas->temporary.alloc);
13403 NK_ASSERT(atlas->temporary.free);
13406 NK_ASSERT(config->ttf_blob);
13407 NK_ASSERT(config->ttf_size);
13408 NK_ASSERT(config->size > 0.0f);
13410 if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f||
13411 !atlas->permanent.alloc || !atlas->permanent.free ||
13412 !atlas->temporary.alloc || !atlas->temporary.free)
13416 cfg = (
struct nk_font_config*)
13417 atlas->permanent.alloc(atlas->permanent.userdata,0,
sizeof(
struct nk_font_config));
13418 NK_MEMCPY(cfg, config,
sizeof(*config));
13422 if (!config->merge_mode) {
13424 if (!atlas->config) {
13425 atlas->config = cfg;
13428 struct nk_font_config *i = atlas->config;
13429 while (i->next) i = i->next;
13434 font = (
struct nk_font*)
13435 atlas->permanent.alloc(atlas->permanent.userdata,0,
sizeof(
struct nk_font));
13437 nk_zero(font,
sizeof(*font));
13438 if (!font)
return 0;
13439 font->config = cfg;
13442 if (!atlas->fonts) {
13443 atlas->fonts = font;
13446 struct nk_font *i = atlas->fonts;
13447 while (i->next) i = i->next;
13451 cfg->font = &font->info;
13454 struct nk_font *f = 0;
13455 struct nk_font_config *c = 0;
13456 NK_ASSERT(atlas->font_num);
13459 cfg->font = &f->info;
13467 if (!config->ttf_data_owned_by_atlas) {
13468 cfg->ttf_blob = atlas->permanent.alloc(atlas->permanent.userdata,0, cfg->ttf_size);
13469 NK_ASSERT(cfg->ttf_blob);
13470 if (!cfg->ttf_blob) {
13474 NK_MEMCPY(cfg->ttf_blob, config->ttf_blob, cfg->ttf_size);
13475 cfg->ttf_data_owned_by_atlas = 1;
13481 nk_font_atlas_add_from_memory(
struct nk_font_atlas *atlas,
void *memory,
13482 nk_size size,
float height,
const struct nk_font_config *config)
13484 struct nk_font_config cfg;
13489 NK_ASSERT(atlas->temporary.alloc);
13490 NK_ASSERT(atlas->temporary.free);
13491 NK_ASSERT(atlas->permanent.alloc);
13492 NK_ASSERT(atlas->permanent.free);
13493 if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free || !memory || !size ||
13494 !atlas->permanent.alloc || !atlas->permanent.free)
13497 cfg = (config) ? *config: nk_font_config(height);
13498 cfg.ttf_blob = memory;
13499 cfg.ttf_size = size;
13501 cfg.ttf_data_owned_by_atlas = 0;
13502 return nk_font_atlas_add(atlas, &cfg);
13504 #ifdef NK_INCLUDE_STANDARD_IO 13506 nk_font_atlas_add_from_file(
struct nk_font_atlas *atlas,
const char *file_path,
13507 float height,
const struct nk_font_config *config)
13511 struct nk_font_config cfg;
13514 NK_ASSERT(atlas->temporary.alloc);
13515 NK_ASSERT(atlas->temporary.free);
13516 NK_ASSERT(atlas->permanent.alloc);
13517 NK_ASSERT(atlas->permanent.free);
13519 if (!atlas || !file_path)
return 0;
13520 memory = nk_file_load(file_path, &size, &atlas->permanent);
13521 if (!memory)
return 0;
13523 cfg = (config) ? *config: nk_font_config(height);
13524 cfg.ttf_blob = memory;
13525 cfg.ttf_size = size;
13527 cfg.ttf_data_owned_by_atlas = 1;
13528 return nk_font_atlas_add(atlas, &cfg);
13532 nk_font_atlas_add_compressed(
struct nk_font_atlas *atlas,
13533 void *compressed_data,
nk_size compressed_size,
float height,
13534 const struct nk_font_config *config)
13536 unsigned int decompressed_size;
13537 void *decompressed_data;
13538 struct nk_font_config cfg;
13541 NK_ASSERT(atlas->temporary.alloc);
13542 NK_ASSERT(atlas->temporary.free);
13543 NK_ASSERT(atlas->permanent.alloc);
13544 NK_ASSERT(atlas->permanent.free);
13546 NK_ASSERT(compressed_data);
13547 NK_ASSERT(compressed_size);
13548 if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free ||
13549 !atlas->permanent.alloc || !atlas->permanent.free)
13552 decompressed_size = nk_decompress_length((
unsigned char*)compressed_data);
13553 decompressed_data = atlas->permanent.alloc(atlas->permanent.userdata,0,decompressed_size);
13554 NK_ASSERT(decompressed_data);
13555 if (!decompressed_data)
return 0;
13556 nk_decompress((
unsigned char*)decompressed_data, (
unsigned char*)compressed_data,
13557 (
unsigned int)compressed_size);
13559 cfg = (config) ? *config: nk_font_config(height);
13560 cfg.ttf_blob = decompressed_data;
13561 cfg.ttf_size = decompressed_size;
13563 cfg.ttf_data_owned_by_atlas = 1;
13564 return nk_font_atlas_add(atlas, &cfg);
13567 nk_font_atlas_add_compressed_base85(
struct nk_font_atlas *atlas,
13568 const char *data_base85,
float height,
const struct nk_font_config *config)
13570 int compressed_size;
13571 void *compressed_data;
13572 struct nk_font *font;
13575 NK_ASSERT(atlas->temporary.alloc);
13576 NK_ASSERT(atlas->temporary.free);
13577 NK_ASSERT(atlas->permanent.alloc);
13578 NK_ASSERT(atlas->permanent.free);
13580 NK_ASSERT(data_base85);
13581 if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free ||
13582 !atlas->permanent.alloc || !atlas->permanent.free)
13585 compressed_size = (((int)
nk_strlen(data_base85) + 4) / 5) * 4;
13586 compressed_data = atlas->temporary.alloc(atlas->temporary.userdata,0, (
nk_size)compressed_size);
13587 NK_ASSERT(compressed_data);
13588 if (!compressed_data)
return 0;
13589 nk_decode_85((
unsigned char*)compressed_data, (
const unsigned char*)data_base85);
13590 font = nk_font_atlas_add_compressed(atlas, compressed_data,
13591 (
nk_size)compressed_size, height, config);
13592 atlas->temporary.free(atlas->temporary.userdata, compressed_data);
13596 #ifdef NK_INCLUDE_DEFAULT_FONT 13598 nk_font_atlas_add_default(
struct nk_font_atlas *atlas,
13599 float pixel_height,
const struct nk_font_config *config)
13602 NK_ASSERT(atlas->temporary.alloc);
13603 NK_ASSERT(atlas->temporary.free);
13604 NK_ASSERT(atlas->permanent.alloc);
13605 NK_ASSERT(atlas->permanent.free);
13606 return nk_font_atlas_add_compressed_base85(atlas,
13607 nk_proggy_clean_ttf_compressed_data_base85, pixel_height, config);
13611 nk_font_atlas_bake(
struct nk_font_atlas *atlas,
int *width,
int *height,
13612 enum nk_font_atlas_format fmt)
13617 struct nk_font *font_iter;
13618 struct nk_font_baker *baker;
13621 NK_ASSERT(atlas->temporary.alloc);
13622 NK_ASSERT(atlas->temporary.free);
13623 NK_ASSERT(atlas->permanent.alloc);
13624 NK_ASSERT(atlas->permanent.free);
13628 if (!atlas || !width || !height ||
13629 !atlas->temporary.alloc || !atlas->temporary.free ||
13630 !atlas->permanent.alloc || !atlas->permanent.free)
13633 #ifdef NK_INCLUDE_DEFAULT_FONT 13635 if (!atlas->font_num)
13636 atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0);
13638 NK_ASSERT(atlas->font_num);
13639 if (!atlas->font_num)
return 0;
13642 nk_font_baker_memory(&tmp_size, &atlas->glyph_count, atlas->config, atlas->font_num);
13643 tmp = atlas->temporary.alloc(atlas->temporary.userdata,0, tmp_size);
13645 if (!tmp)
goto failed;
13648 baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary);
13649 atlas->glyphs = (
struct nk_font_glyph*)atlas->permanent.alloc(
13650 atlas->permanent.userdata,0,
sizeof(
struct nk_font_glyph)*(
nk_size)atlas->glyph_count);
13651 NK_ASSERT(atlas->glyphs);
13652 if (!atlas->glyphs)
13656 atlas->custom.w = (NK_CURSOR_DATA_W*2)+1;
13657 atlas->custom.h = NK_CURSOR_DATA_H + 1;
13658 if (!nk_font_bake_pack(baker, &img_size, width, height, &atlas->custom,
13659 atlas->config, atlas->font_num, &atlas->temporary))
13663 atlas->pixel = atlas->temporary.alloc(atlas->temporary.userdata,0, img_size);
13664 NK_ASSERT(atlas->pixel);
13669 nk_font_bake(baker, atlas->pixel, *width, *height,
13670 atlas->glyphs, atlas->glyph_count, atlas->config, atlas->font_num);
13671 nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom,
13672 nk_custom_cursor_data, NK_CURSOR_DATA_W, NK_CURSOR_DATA_H,
'.',
'X');
13674 if (fmt == NK_FONT_ATLAS_RGBA32) {
13676 void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0,
13677 (
nk_size)(*width * *height * 4));
13678 NK_ASSERT(img_rgba);
13679 if (!img_rgba)
goto failed;
13680 nk_font_bake_convert(img_rgba, *width, *height, atlas->pixel);
13681 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13682 atlas->pixel = img_rgba;
13684 atlas->tex_width = *width;
13685 atlas->tex_height = *height;
13688 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13689 struct nk_font *font = font_iter;
13690 struct nk_font_config *config = font->config;
13691 nk_font_init(font, config->size, config->fallback_glyph, atlas->glyphs,
13698 {{ 0, 3}, {12,19}, { 0, 0}},
13699 {{13, 0}, { 7,16}, { 4, 8}},
13700 {{31, 0}, {23,23}, {11,11}},
13701 {{21, 0}, { 9, 23}, { 5,11}},
13702 {{55,18}, {23, 9}, {11, 5}},
13703 {{73, 0}, {17,17}, { 9, 9}},
13704 {{55, 0}, {17,17}, { 9, 9}}
13707 struct nk_cursor *cursor = &atlas->cursors[i];
13708 cursor->
img.
w = (
unsigned short)*width;
13709 cursor->
img.
h = (
unsigned short)*height;
13710 cursor->
img.
region[0] = (
unsigned short)(atlas->custom.x + nk_cursor_data[i][0].x);
13711 cursor->
img.
region[1] = (
unsigned short)(atlas->custom.y + nk_cursor_data[i][0].y);
13712 cursor->
img.
region[2] = (
unsigned short)nk_cursor_data[i][1].x;
13713 cursor->
img.
region[3] = (
unsigned short)nk_cursor_data[i][1].y;
13714 cursor->size = nk_cursor_data[i][1];
13715 cursor->
offset = nk_cursor_data[i][2];
13718 atlas->temporary.free(atlas->temporary.userdata, tmp);
13719 return atlas->pixel;
13723 if (tmp) atlas->temporary.free(atlas->temporary.userdata, tmp);
13724 if (atlas->glyphs) {
13725 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
13728 if (atlas->pixel) {
13729 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13735 nk_font_atlas_end(
struct nk_font_atlas *atlas,
nk_handle texture,
13739 struct nk_font *font_iter;
13748 null->
uv.
x = (atlas->custom.x + 0.5f)/(
float)atlas->tex_width;
13749 null->
uv.
y = (atlas->custom.y + 0.5f)/(
float)atlas->tex_height;
13751 for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
13752 font_iter->texture = texture;
13753 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 13754 font_iter->handle.texture = texture;
13758 atlas->cursors[i].img.handle = texture;
13760 atlas->temporary.free(atlas->temporary.userdata, atlas->pixel);
13762 atlas->tex_width = 0;
13763 atlas->tex_height = 0;
13764 atlas->custom.x = 0;
13765 atlas->custom.y = 0;
13766 atlas->custom.w = 0;
13767 atlas->custom.h = 0;
13770 nk_font_atlas_cleanup(
struct nk_font_atlas *atlas)
13773 NK_ASSERT(atlas->temporary.alloc);
13774 NK_ASSERT(atlas->temporary.free);
13775 NK_ASSERT(atlas->permanent.alloc);
13776 NK_ASSERT(atlas->permanent.free);
13777 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free)
return;
13778 if (atlas->config) {
13779 struct nk_font_config *iter;
13780 for (iter = atlas->config; iter; iter = iter->next) {
13781 struct nk_font_config *i;
13782 for (i = iter->n; i != iter; i = i->n) {
13783 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13786 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13787 iter->ttf_blob = 0;
13792 nk_font_atlas_clear(
struct nk_font_atlas *atlas)
13795 NK_ASSERT(atlas->temporary.alloc);
13796 NK_ASSERT(atlas->temporary.free);
13797 NK_ASSERT(atlas->permanent.alloc);
13798 NK_ASSERT(atlas->permanent.free);
13799 if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free)
return;
13801 if (atlas->config) {
13802 struct nk_font_config *iter, *next;
13803 for (iter = atlas->config; iter; iter = next) {
13804 struct nk_font_config *i, *n;
13805 for (i = iter->n; i != iter; i = n) {
13808 atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob);
13809 atlas->permanent.free(atlas->permanent.userdata, i);
13813 atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
13814 atlas->permanent.free(atlas->permanent.userdata, iter);
13818 if (atlas->fonts) {
13819 struct nk_font *iter, *next;
13820 for (iter = atlas->fonts; iter; iter = next) {
13822 atlas->permanent.free(atlas->permanent.userdata, iter);
13827 atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
14096 #define NK_COLOR_MAP(NK_COLOR)\ 14097 NK_COLOR(NK_COLOR_TEXT, 175,175,175,255) \ 14098 NK_COLOR(NK_COLOR_WINDOW, 45, 45, 45, 255) \ 14099 NK_COLOR(NK_COLOR_HEADER, 40, 40, 40, 255) \ 14100 NK_COLOR(NK_COLOR_BORDER, 65, 65, 65, 255) \ 14101 NK_COLOR(NK_COLOR_BUTTON, 50, 50, 50, 255) \ 14102 NK_COLOR(NK_COLOR_BUTTON_HOVER, 40, 40, 40, 255) \ 14103 NK_COLOR(NK_COLOR_BUTTON_ACTIVE, 35, 35, 35, 255) \ 14104 NK_COLOR(NK_COLOR_TOGGLE, 100,100,100,255) \ 14105 NK_COLOR(NK_COLOR_TOGGLE_HOVER, 120,120,120,255) \ 14106 NK_COLOR(NK_COLOR_TOGGLE_CURSOR, 45, 45, 45, 255) \ 14107 NK_COLOR(NK_COLOR_SELECT, 45, 45, 45, 255) \ 14108 NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \ 14109 NK_COLOR(NK_COLOR_SLIDER, 38, 38, 38, 255) \ 14110 NK_COLOR(NK_COLOR_SLIDER_CURSOR, 100,100,100,255) \ 14111 NK_COLOR(NK_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \ 14112 NK_COLOR(NK_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \ 14113 NK_COLOR(NK_COLOR_PROPERTY, 38, 38, 38, 255) \ 14114 NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \ 14115 NK_COLOR(NK_COLOR_EDIT_CURSOR, 175,175,175,255) \ 14116 NK_COLOR(NK_COLOR_COMBO, 45, 45, 45, 255) \ 14117 NK_COLOR(NK_COLOR_CHART, 120,120,120,255) \ 14118 NK_COLOR(NK_COLOR_CHART_COLOR, 45, 45, 45, 255) \ 14119 NK_COLOR(NK_COLOR_CHART_COLOR_HIGHLIGHT, 255, 0, 0, 255) \ 14120 NK_COLOR(NK_COLOR_SCROLLBAR, 40, 40, 40, 255) \ 14121 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \ 14122 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \ 14123 NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \ 14124 NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) 14128 #define NK_COLOR(a,b,c,d,e) {b,c,d,e}, 14129 NK_COLOR_MAP(NK_COLOR)
14133 #define NK_COLOR(a,b,c,d,e) #a, 14134 NK_COLOR_MAP(NK_COLOR)
14141 return nk_color_names[c];
14148 i.data.image = img;
14156 i.data.color = col;
14164 i.data.color =
nk_rgba(0,0,0,0);
14187 style = &ctx->
style;
14188 table = (!table) ? nk_default_color_style: table;
14191 text = &style->
text;
14196 button = &style->
button;
14276 toggle = &style->
option;
14318 slider = &style->
slider;
14429 edit = &style->
edit;
14467 property->padding =
nk_vec2(4,4);
14468 property->border = 1;
14469 property->rounding = 10;
14470 property->draw_begin = 0;
14471 property->draw_end = 0;
14518 chart = &style->
chart;
14529 combo = &style->
combo;
14718 style = &ctx->
style;
14727 struct nk_config_stack_user_font *font_stack;
14728 struct nk_config_stack_user_font_element *element;
14731 if (!ctx)
return 0;
14734 NK_ASSERT(font_stack->head < (
int)
NK_LEN(font_stack->elements));
14735 if (font_stack->head >= (
int)
NK_LEN(font_stack->elements))
14738 element = &font_stack->elements[font_stack->head++];
14747 struct nk_config_stack_user_font *font_stack;
14748 struct nk_config_stack_user_font_element *element;
14751 if (!ctx)
return 0;
14754 NK_ASSERT(font_stack->head > 0);
14755 if (font_stack->head < 1)
14758 element = &font_stack->elements[--font_stack->head];
14759 *element->address = element->old_value;
14762 #define NK_STYLE_PUSH_IMPLEMENATION(prefix, type, stack) \ 14763 nk_style_push_##type(struct nk_context *ctx, prefix##_##type *address, prefix##_##type value)\ 14765 struct nk_config_stack_##type * type_stack;\ 14766 struct nk_config_stack_##type##_element *element;\ 14768 if (!ctx) return 0;\ 14769 type_stack = &ctx->stacks.stack;\ 14770 NK_ASSERT(type_stack->head < (int)NK_LEN(type_stack->elements));\ 14771 if (type_stack->head >= (int)NK_LEN(type_stack->elements))\ 14773 element = &type_stack->elements[type_stack->head++];\ 14774 element->address = address;\ 14775 element->old_value = *address;\ 14779 #define NK_STYLE_POP_IMPLEMENATION(type, stack) \ 14780 nk_style_pop_##type(struct nk_context *ctx)\ 14782 struct nk_config_stack_##type *type_stack;\ 14783 struct nk_config_stack_##type##_element *element;\ 14785 if (!ctx) return 0;\ 14786 type_stack = &ctx->stacks.stack;\ 14787 NK_ASSERT(type_stack->head > 0);\ 14788 if (type_stack->head < 1)\ 14790 element = &type_stack->elements[--type_stack->head];\ 14791 *element->address = element->old_value;\ 14794 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk, style_item, style_items)
14795 NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,
float, floats)
14796 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk, vec2, vectors)
14797 NK_API int NK_STYLE_PUSH_IMPLEMENATION(nk,flags, flags)
14798 NK_API int NK_STYLE_PUSH_IMPLEMENATION(
struct nk,color, colors)
14800 NK_API int NK_STYLE_POP_IMPLEMENATION(style_item, style_items)
14801 NK_API int NK_STYLE_POP_IMPLEMENATION(
float,floats)
14802 NK_API int NK_STYLE_POP_IMPLEMENATION(vec2, vectors)
14803 NK_API int NK_STYLE_POP_IMPLEMENATION(flags,flags)
14804 NK_API int NK_STYLE_POP_IMPLEMENATION(color,colors)
14811 if (!ctx)
return 0;
14812 style = &ctx->
style;
14836 style = &ctx->
style;
14846 style = &ctx->
style;
14870 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT 14871 nk_draw_list_init(&ctx->draw_list);
14874 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 14879 alloc.userdata.ptr = 0;
14880 alloc.alloc = nk_malloc;
14881 alloc.free = nk_mfree;
14890 if (!memory)
return 0;
14891 nk_setup(ctx, font);
14902 if (!cmds || !pool)
return 0;
14904 nk_setup(ctx, font);
14912 nk_pool_init(&ctx->
pool,
alloc, NK_POOL_DEFAULT_CAPACITY);
14922 if (!
alloc)
return 0;
14923 nk_setup(ctx, font);
14925 nk_pool_init(&ctx->
pool,
alloc, NK_POOL_DEFAULT_CAPACITY);
14929 #ifdef NK_INCLUDE_COMMAND_USERDATA 14934 ctx->userdata = handle;
14946 nk_pool_free(&ctx->
pool);
14985 iter->
seq == ctx->
seq) {
15002 nk_free_window(ctx, iter->
popup.
win);
15009 if (it->
seq != ctx->
seq) {
15010 nk_remove_table(iter, it);
15012 nk_free_table(ctx, it);
15020 nk_remove_window(ctx, iter);
15021 nk_free_window(ctx, iter);
15023 }
else iter = iter->
next;
15032 if (!ctx || !buffer)
return;
15036 buffer->
clip = nk_null_rect;
15043 nk_start_buffer(ctx, &win->
buffer);
15051 if (!ctx || !win)
return;
15067 if (!ctx || !win)
return;
15078 if (!ctx || !buffer)
return;
15090 if (!ctx || !win)
return;
15091 nk_finish_buffer(ctx, &win->
buffer);
15097 parent_last->
next = buf->
end;
15113 nk_start_buffer(ctx, &ctx->
overlay);
15117 mouse_bounds.w = cursor->size.x;
15118 mouse_bounds.h = cursor->size.y;
15121 nk_finish_buffer(ctx, &ctx->
overlay);
15167 if (!ctx)
return 0;
15168 if (!ctx->
count)
return 0;
15179 if (!iter)
return 0;
15189 if (!ctx || !cmd || !ctx->
count)
return 0;
15208 unsigned int capacity)
15210 nk_zero(pool,
sizeof(*pool));
15211 pool->
alloc = *alloc;
15217 nk_pool_free(
struct nk_pool *pool)
15231 nk_zero(pool,
sizeof(*pool));
15240 nk_pool_alloc(
struct nk_pool *pool)
15246 NK_ASSERT(pool->
pages);
15247 if (!pool->
pages)
return 0;
15254 page->next = pool->
pages;
15255 pool->
pages = page;
15271 nk_create_page_element(
struct nk_context *ctx)
15280 elem = nk_pool_alloc(&ctx->
pool);
15282 if (!elem)
return 0;
15289 if (!elem)
return 0;
15297 nk_link_page_element_into_freelist(
struct nk_context *ctx,
15313 nk_link_page_element_into_freelist(ctx, elem);
15317 {
void *elem_end = (
void*)(elem + 1);
15319 if (elem_end == buffer_end)
15321 else nk_link_page_element_into_freelist(ctx, elem);}
15337 elem = nk_create_page_element(ctx);
15338 if (!elem)
return 0;
15347 nk_free_page_element(ctx, pe);
15385 if (!win || !ctx)
return 0;
15387 struct nk_table *tbl = nk_create_table(ctx);
15389 if (!tbl)
return 0;
15390 nk_push_table(win, tbl);
15402 unsigned int i = 0;
15404 for (i = 0; i <
size; ++i) {
15405 if (iter->
keys[i] == name) {
15407 return &iter->
values[i];
15428 elem = nk_create_page_element(ctx);
15429 if (!elem)
return 0;
15438 nk_free_page_element(ctx, pe);
15441 nk_panel_has_header(
nk_flags flags,
const char *title)
15488 case NK_PANEL_MENU:
return style->window.menu_border_color;
15511 struct nk_vec2 scrollbar_size;
15512 struct nk_vec2 panel_padding;
15525 style = &ctx->
style;
15526 font = style->
font;
15531 #ifdef NK_INCLUDE_COMMAND_USERDATA
15536 panel_padding = nk_panel_get_padding(style, panel_type);
15540 int left_mouse_down;
15541 int left_mouse_click_in_cursor;
15548 if (nk_panel_has_header(win->
flags, title)) {
15551 }
else header.h = panel_padding.y;
15557 if (left_mouse_down && left_mouse_click_in_cursor) {
15567 layout->
type = panel_type;
15570 layout->
bounds.
x += panel_padding.x;
15571 layout->
bounds.
w -= 2*panel_padding.x;
15573 layout->
border = nk_panel_get_border(style, win->
flags, panel_type);
15575 }
else layout->
border = 0;
15590 layout->
bounds.
w -= scrollbar_size.x;
15591 if (!nk_panel_is_nonblock(panel_type)) {
15599 if (nk_panel_has_header(win->
flags, title))
15614 layout->
bounds.
y += header.h;
15615 layout->
bounds.
h -= header.h;
15616 layout->
at_y += header.h;
15619 if (ctx->
active == win) {
15633 text.background =
nk_rgba(0,0,0,0);
15636 text.background = background->
data.
color;
15644 button.w = button.h;
15655 if (nk_do_button_symbol(&ws, &win->
buffer, button,
15668 button.x = (header.w + header.x) - button.w;
15675 button.x = header.x;
15688 struct nk_rect label = {0,0,0,0};
15697 label.
w =
NK_CLAMP(0, label.
w, header.x + header.w - label.
x);
15698 nk_widget_text(out, label,(
const char*)title, text_len, &text,
NK_TEXT_LEFT, font);}
15719 layout->
clip = clip;}
15731 struct nk_vec2 scrollbar_size;
15732 struct nk_vec2 panel_padding;
15741 layout = window->
layout;
15742 style = &ctx->
style;
15745 if (!nk_panel_is_sub(layout->
type))
15750 panel_padding = nk_panel_get_padding(style, layout->
type);
15764 empty_space.x = window->
bounds.
x;
15765 empty_space.y = layout->
bounds.
y;
15766 empty_space.h = panel_padding.y;
15767 empty_space.w = window->
bounds.
w;
15771 empty_space.x = window->
bounds.
x;
15772 empty_space.y = layout->
bounds.
y;
15773 empty_space.w = panel_padding.x + layout->
border;
15774 empty_space.h = layout->
bounds.
h;
15779 empty_space.y = layout->
bounds.
y;
15780 empty_space.w = panel_padding.x + layout->
border;
15781 empty_space.h = layout->
bounds.
h;
15783 empty_space.w += scrollbar_size.x;
15788 empty_space.x = window->
bounds.
x;
15790 empty_space.w = window->
bounds.
w;
15791 empty_space.h = scrollbar_size.y;
15802 int scroll_has_scrolling;
15803 float scroll_target;
15804 float scroll_offset;
15809 if (nk_panel_is_sub(layout->
type))
15812 struct nk_window *root_window = window;
15814 while (root_panel->
parent)
15815 root_panel = root_panel->
parent;
15816 while (root_window->
parent)
15817 root_window = root_window->
parent;
15820 scroll_has_scrolling = 0;
15828 root_panel = window->
layout;
15829 while (root_panel->
parent) {
15831 root_panel = root_panel->
parent;
15834 scroll_has_scrolling =
nk_true;
15837 }
else if (!nk_panel_is_sub(layout->
type)) {
15843 }
else scroll_has_scrolling =
nk_false;
15848 scroll.x = layout->
bounds.
x + layout->
bounds.
w + panel_padding.x;
15850 scroll.w = scrollbar_size.x;
15853 scroll_offset = (float)*layout->
offset_y;
15854 scroll_step = scroll.h * 0.10f;
15855 scroll_inc = scroll.h * 0.01f;
15856 scroll_target = (
float)(int)(layout->
at_y - scroll.y);
15857 scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling,
15858 scroll_offset, scroll_target, scroll_step, scroll_inc,
15861 if (in && scroll_has_scrolling)
15870 scroll.h = scrollbar_size.y;
15872 scroll_offset = (float)*layout->
offset_x;
15873 scroll_target = (
float)(int)(layout->
max_x - scroll.x);
15874 scroll_step = layout->
max_x * 0.05f;
15875 scroll_inc = layout->
max_x * 0.005f;
15876 scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling,
15877 scroll_offset, scroll_target, scroll_step, scroll_inc,
15888 if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active))
15896 struct nk_color border_color = nk_panel_get_border_color(style, layout->
type);
15903 b.
h = padding_y - window->
bounds.
y;
15912 scaler.
w = scrollbar_size.x;
15913 scaler.h = scrollbar_size.y;
15916 scaler.x = layout->
bounds.
x - panel_padding.x * 0.5f;
15917 else scaler.x = layout->
bounds.
x + layout->
bounds.
w + panel_padding.x;
15919 scaler.x -= scaler.w;
15928 scaler.y + scaler.h, scaler.x + scaler.w,
15929 scaler.y + scaler.h, item->
data.
color);
15932 scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->
data.
color);
15943 if (left_mouse_down && left_mouse_click_in_scaler) {
15946 delta_x = -delta_x;
15950 if (window->
bounds.
w + delta_x >= window_size.
x) {
15951 if ((delta_x < 0) || (delta_x > 0 && in->
mouse.
pos.
x >= scaler.x)) {
15971 if (!nk_panel_is_sub(layout->
type)) {
15974 nk_command_buffer_reset(&window->
buffer);
15976 else nk_finish(ctx, window);
15998 nk_zero(&window->
edit,
sizeof(window->
edit));
16031 elem = nk_create_page_element(ctx);
16032 if (!elem)
return 0;
16042 nk_free_window(ctx, win->
popup.
win);
16051 nk_remove_table(win, it);
16052 nk_free_table(ctx, it);
16061 nk_free_page_element(ctx, pe);}
16069 NK_ASSERT(iter != iter->
next);
16070 if (iter->
name == hash) {
16081 enum nk_window_insert_location loc)
16086 if (!win || !ctx)
return;
16090 NK_ASSERT(iter != iter->
next);
16091 NK_ASSERT(iter != win);
16092 if (iter == win)
return;
16104 if (loc == NK_INSERT_BACK) {
16127 if (win == ctx->
begin || win == ctx->
end) {
16128 if (win == ctx->
begin) {
16133 if (win == ctx->
end) {
16173 NK_ASSERT(!ctx->
current &&
"if this triggers you missed a `nk_end` call");
16174 if (!ctx || ctx->
current || !title || !name)
16178 style = &ctx->
style;
16181 win = nk_find_window(ctx, title_hash, name);
16185 win = (
struct nk_window*)nk_create_window(ctx);
16187 if (!win)
return 0;
16190 nk_insert_window(ctx, win, NK_INSERT_FRONT);
16191 else nk_insert_window(ctx, win, NK_INSERT_BACK);
16196 win->
name = title_hash;
16216 NK_ASSERT(win->
seq != ctx->
seq);
16227 }
else nk_start(ctx, win);
16232 int inpanel, ishovered;
16249 iter_bounds.
x, iter_bounds.
y, iter_bounds.
w, iter_bounds.
h) &&
16263 if (iter && inpanel && (win != ctx->
end)) {
16270 iter_bounds.
x, iter_bounds.
y, iter_bounds.
w, iter_bounds.
h) &&
16288 nk_remove_window(ctx, iter);
16289 nk_insert_window(ctx, iter, NK_INSERT_BACK);
16292 if (!iter && ctx->
end != win) {
16296 nk_remove_window(ctx, win);
16297 nk_insert_window(ctx, win, NK_INSERT_BACK);
16318 NK_ASSERT(ctx->
current &&
"if this triggers you forgot to call `nk_begin`");
16360 if (!ctx || !ctx->
current)
return 0;
16368 if (!ctx || !ctx->
current)
return 0;
16413 if (!ctx || !ctx->
current)
return 0;
16421 if (!ctx || !ctx->
current)
return 0;
16430 if (!ctx || !ctx->
current)
return 0;
16438 if (!ctx || !ctx->
current)
return 0;
16448 if (!ctx)
return 0;
16475 return any_hovered || any_active;
16484 if (!ctx)
return 0;
16488 win = nk_find_window(ctx, title_hash,
name);
16489 if (!win)
return 0;
16499 if (!ctx)
return 1;
16503 win = nk_find_window(ctx, title_hash,
name);
16504 if (!win)
return 1;
16514 if (!ctx)
return 1;
16518 win = nk_find_window(ctx, title_hash,
name);
16519 if (!win)
return 1;
16529 if (!ctx)
return 0;
16533 win = nk_find_window(ctx, title_hash,
name);
16534 if (!win)
return 0;
16535 return win == ctx->
active;
16544 return nk_find_window(ctx, title_hash,
name);
16554 NK_ASSERT(ctx->
current != win &&
"You cannot close a currently active window");
16555 if (ctx->
current == win)
return;
16568 NK_ASSERT(ctx->
current != win &&
"You cannot update a currently in procecss window");
16601 win = nk_find_window(ctx, title_hash,
name);
16612 if (!ctx || !cond)
return;
16626 win = nk_find_window(ctx, title_hash,
name);
16637 if (!ctx || !cond)
return;
16652 win = nk_find_window(ctx, title_hash,
name);
16653 if (win && ctx->
end != win) {
16654 nk_remove_window(ctx, win);
16655 nk_insert_window(ctx, win, NK_INSERT_BACK);
16697 popup = (
struct nk_window*)nk_create_window(ctx);
16698 popup->parent = win;
16720 popup->parent = win;
16721 popup->bounds = rect;
16730 nk_start_popup(ctx, win);
16760 nk_free_panel(ctx, popup->
layout);
16789 popup = (
struct nk_window*)nk_create_window(ctx);
16790 popup->parent = win;
16796 int pressed, in_body, in_header;
16800 if (pressed && (!in_body || in_header))
16822 NK_ASSERT(popup->
layout);
16824 nk_start_popup(ctx, win);
16829 nk_panel_begin(ctx, 0, panel_type);
16849 if (!ctx || !ctx->
current)
return;
16852 NK_ASSERT(
popup->parent);
16869 if (!
popup->parent)
return;
16870 win =
popup->parent;
16884 nk_finish_popup(ctx, win);
16900 struct nk_rect trigger_bounds)
16907 int is_clicked = 0;
16930 if ((!is_open && !is_clicked))
16975 style = &ctx->
style;
16994 const char *text,
int len,
nk_flags align)
17010 style = &ctx->
style;
17024 const char *label,
nk_flags align)
17030 const char *text,
int len,
nk_flags align)
17046 style = &ctx->
style;
17080 if (!ctx || !ctx->
current)
return;
17084 NK_ASSERT(popup->
parent);
17092 struct nk_rect body = {0,0,0,0};
17101 if (pressed && in_body)
17190 const char *
id,
int is_clicked,
struct nk_rect header,
struct nk_vec2 size)
17206 body.
y = header.
y + header.
h;
17212 if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
17213 (!is_open && !is_active && !is_clicked))
return 0;
17239 if (!state)
return 0;
17244 return nk_menu_begin(ctx, win, title, is_clicked, header, size);
17269 if (!state)
return 0;
17274 return nk_menu_begin(ctx, win,
id, is_clicked, header, size);
17294 if (!state)
return 0;
17299 return nk_menu_begin(ctx, win,
id, is_clicked, header, size);
17319 if (!state)
return 0;
17325 return nk_menu_begin(ctx, win, title, is_clicked, header, size);
17351 if (!state)
return 0;
17357 return nk_menu_begin(ctx, win, title, is_clicked, header, size);
17377 const char *label,
nk_flags align)
17383 const char *text,
int len,
nk_flags align)
17388 const char *text,
int len,
nk_flags align)
17393 const char *label,
nk_flags align)
17452 float total_space,
int columns)
17454 float panel_padding;
17455 float panel_spacing;
17462 padding = nk_panel_get_padding(style, type);
17465 panel_padding = 2 * padding.x;
17466 panel_spacing = (float)
NK_MAX(columns - 1, 0) * spacing.x;
17467 panel_space = total_space - panel_padding - panel_spacing;
17468 return panel_space;
17472 float height,
int cols)
17489 style = &ctx->
style;
17507 if (height == 0.0f)
17509 else layout->
row.
height = height + item_spacing.y;
17515 background.x = win->
bounds.
x;
17516 background.w = win->
bounds.
w;
17517 background.y = layout->
at_y - 1.0f;
17518 background.h = layout->
row.
height + 1.0f;
17524 float height,
int cols,
int width)
17535 nk_panel_layout(ctx, win, height, cols);
17550 NK_ASSERT(pixel_width);
17567 float row_height,
int cols)
17580 nk_panel_layout(ctx, win, row_height, cols);
17610 float ratio = ratio_or_width;
17611 if ((ratio + layout->
row.
filled) > 1.0f)
return;
17639 float height,
int cols,
const float *ratio)
17654 nk_panel_layout(ctx, win, height, cols);
17659 for (i = 0; i < cols; ++i) {
17660 if (ratio[i] < 0.0f)
17662 else r += ratio[i];
17666 layout->
row.
item_width = (r > 0 && n_undef > 0) ? (r / (
float)n_undef):0;
17690 nk_panel_layout(ctx, win, height, 1);
17770 int variable_count = 0;
17771 int min_variable_count = 0;
17772 float min_fixed_width = 0.0f;
17773 float total_fixed_width = 0.0f;
17774 float max_variable_width = 0.0f;
17788 if (width >= 0.0f) {
17789 total_fixed_width += width;
17790 min_fixed_width += width;
17791 }
else if (width < -1.0f) {
17793 total_fixed_width += width;
17794 max_variable_width =
NK_MAX(max_variable_width, width);
17797 min_variable_count++;
17801 if (variable_count) {
17802 float space = nk_layout_row_calculate_usable_space(&ctx->
style, layout->
type,
17804 float var_width = (
NK_MAX(space-min_fixed_width,0.0f)) / (
float)variable_count;
17805 int enough_space = var_width >= max_variable_width;
17807 var_width = (
NK_MAX(space-total_fixed_width,0)) / (
float)min_variable_count;
17810 *width = (*width >= 0.0f)? *width: (*width < -1.0f && !enough_space)? -(*width): var_width;
17816 float height,
int widget_count)
17829 nk_panel_layout(ctx, win, height, widget_count);
17887 ret.x = layout->
clip.
x;
17888 ret.y = layout->
clip.
y;
17889 ret.w = layout->
clip.
w;
17906 ret.x = layout->
at_x;
17907 ret.y = layout->
at_y;
17919 NK_ASSERT(ctx->current);
17920 NK_ASSERT(ctx->current->layout);
17921 win = ctx->current;
17935 NK_ASSERT(ctx->current);
17936 NK_ASSERT(ctx->current->layout);
17937 win = ctx->current;
17951 NK_ASSERT(ctx->current);
17952 NK_ASSERT(ctx->current->layout);
17953 win = ctx->current;
17967 NK_ASSERT(ctx->current);
17968 NK_ASSERT(ctx->current->layout);
17969 win = ctx->current;
17981 const float row_height = layout->
row.
height - spacing.
y;
17982 nk_panel_layout(ctx, win, row_height, layout->
row.
columns);
17994 float item_offset = 0;
17995 float item_width = 0;
17996 float item_spacing = 0;
17997 float panel_space = 0;
18007 style = &ctx->
style;
18011 padding = nk_panel_get_padding(style, layout->
type);
18012 panel_space = nk_layout_row_calculate_usable_space(&ctx->
style, layout->
type,
18020 item_offset = (
float)layout->
row.
index * item_width;
18021 item_spacing = (float)layout->
row.
index * spacing.x;
18052 item_spacing = (
float)layout->
row.
index * spacing.x;
18053 item_width = (ratio * panel_space);
18064 item_offset = (float)layout->
row.
index * item_width;
18065 item_spacing = (
float)layout->
row.
index * spacing.x;
18071 item_spacing = (float)layout->
row.
index * spacing.x;
18078 if (((bounds->
x + bounds->
w) > layout->
max_x) && modify)
18079 layout->
max_x = (bounds->
x + bounds->
w);
18088 item_spacing = (float)layout->
row.
index * spacing.x;
18099 item_spacing = (float)layout->
row.
index * spacing.x;
18102 default: NK_ASSERT(0);
break;
18106 bounds->
w = item_width;
18109 bounds->
x = layout->
at_x + item_offset + item_spacing + padding.x;
18110 if (((bounds->
x + bounds->
w) > layout->
max_x) && modify)
18111 layout->
max_x = bounds->
x + bounds->
w;
18130 nk_panel_alloc_row(ctx, win);
18189 struct nk_rect header = {0,0,0,0};
18190 struct nk_rect sym = {0,0,0,0};
18206 style = &ctx->
style;
18215 widget_state =
nk_widget(&header, ctx);
18220 text.background =
nk_rgba(0,0,0,0);
18222 text.background = background->
data.
color;
18253 button, 0, style->
font);
18257 sym.
x = sym.
x + sym.
w + 4 * item_spacing.x;
18264 header.
w =
NK_MAX(header.
w, sym.
w + item_spacing.x);
18265 label.x = sym.
x + sym.
w + item_spacing.x;
18267 label.w = header.
w - (sym.
w + item_spacing.y + style->
tab.
indent);
18271 nk_widget_text(out, label, title,
nk_strlen(title), &text,
18286 const char *hash,
int len,
int line)
18298 state = nk_find_value(win, tree_hash);
18300 state = nk_add_value(ctx, win, tree_hash, 0);
18301 *state = initial_state;
18309 return nk_tree_state_base(ctx, type, 0, title, state);
18315 return nk_tree_state_base(ctx, type, &img, title, state);
18339 const char *hash,
int len,
int line)
18341 return nk_tree_base(ctx,
type, 0, title, initial_state, hash, len, line);
18346 const char *hash,
int len,
int seed)
18348 return nk_tree_base(ctx,
type, &img, title, initial_state, hash, len, seed);
18357 struct nk_image *img,
const char *title,
int title_len,
18374 struct nk_rect header = {0,0,0,0};
18375 struct nk_rect sym = {0,0,0,0};
18391 style = &ctx->
style;
18401 widget_state =
nk_widget(&header, ctx);
18406 text.background =
nk_rgba(0,0,0,0);
18408 text.background = background->
data.
color;
18443 text_width += (4 * padding.x);
18445 header.
w =
NK_MAX(header.
w, sym.
w + item_spacing.x);
18446 label.x = sym.
x + sym.
w + item_spacing.x;
18448 label.w =
NK_MIN(header.
w - (sym.
w + item_spacing.y + style->
tab.
indent), text_width);
18454 }
else nk_do_selectable(&dummy, &win->
buffer, label, title, title_len,
NK_TEXT_LEFT,
18469 int *selected,
const char *hash,
int len,
int line)
18481 state = nk_find_value(win, tree_hash);
18483 state = nk_add_value(ctx, win, tree_hash, 0);
18484 *state = initial_state;
18485 }
return nk_tree_element_image_push_hashed_base(ctx, type, img, title,
18491 int *selected,
const char *hash,
int len,
int seed)
18493 return nk_tree_element_base(ctx, type, 0, title, initial_state, selected, hash, len, seed);
18498 int *selected,
const char *hash,
int len,
int seed)
18500 return nk_tree_element_base(ctx, type, &img, title, initial_state, selected, hash, len, seed);
18526 nk_panel_alloc_space(&
bounds, ctx);
18536 nk_zero(&panel,
sizeof(panel));
18538 panel.
flags = flags;
18539 panel.scrollbar.x = *x_offset;
18540 panel.scrollbar.y = *y_offset;
18542 panel.layout = (
struct nk_panel*)nk_create_panel(ctx);
18548 panel.layout->
offset_x = x_offset;
18549 panel.layout->
offset_y = y_offset;
18551 win->
layout = panel.layout;
18575 struct nk_vec2 panel_padding;
18594 pan.bounds.x = g->
bounds.
x - panel_padding.x;
18595 pan.bounds.w = g->
bounds.
w + 2 * panel_padding.x;
18598 pan.bounds.x -= g->
border;
18599 pan.bounds.y -= g->
border;
18600 pan.bounds.w += 2*g->
border;
18601 pan.bounds.h += 2*g->
border;
18609 pan.flags = g->
flags;
18610 pan.buffer = win->
buffer;
18616 nk_unify(&clip, &parent->
clip, pan.bounds.
x, pan.bounds.y,
18617 pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x);
18621 win->
buffer = pan.buffer;
18636 const char *title,
nk_flags flags)
18655 x_offset = nk_find_value(win, id_hash);
18657 x_offset = nk_add_value(ctx, win, id_hash, 0);
18658 y_offset = nk_add_value(ctx, win, id_hash+1, 0);
18660 NK_ASSERT(x_offset);
18661 NK_ASSERT(y_offset);
18662 if (!x_offset || !y_offset)
return 0;
18663 *x_offset = *y_offset = 0;
18664 }
else y_offset = nk_find_value(win, id_hash+1);
18689 const char *title,
nk_flags flags,
int row_height,
int row_count)
18705 if (!ctx || !view || !title)
return 0;
18708 style = &ctx->
style;
18710 row_height +=
NK_MAX(0, (
int)item_spacing.y);
18715 x_offset = nk_find_value(win, title_hash);
18717 x_offset = nk_add_value(ctx, win, title_hash, 0);
18718 y_offset = nk_add_value(ctx, win, title_hash+1, 0);
18720 NK_ASSERT(x_offset);
18721 NK_ASSERT(y_offset);
18722 if (!x_offset || !y_offset)
return 0;
18723 *x_offset = *y_offset = 0;
18724 }
else y_offset = nk_find_value(win, title_hash+1);
18735 view->
count = (int)
NK_MAX(nk_iceilf((layout->
clip.
h)/(float)row_height),0);
18749 NK_ASSERT(view->
ctx);
18751 if (!view || !view->
ctx)
return;
18778 nk_layout_peek(&bounds, ctx);
18790 nk_layout_peek(&bounds, ctx);
18802 nk_layout_peek(&bounds, ctx);
18814 nk_layout_peek(&bounds, ctx);
18826 nk_layout_peek(&bounds, ctx);
18840 c.
x = (float)((
int)c.
x);
18841 c.
y = (float)((
int)c.
y);
18842 c.
w = (float)((
int)c.
w);
18843 c.
h = (float)((
int)c.
h);
18845 nk_layout_peek(&bounds, ctx);
18846 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
18862 c.
x = (float)((
int)c.
x);
18863 c.
y = (float)((
int)c.
y);
18864 c.
w = (float)((
int)c.
w);
18865 c.
h = (float)((
int)c.
h);
18867 nk_layout_peek(&bounds, ctx);
18868 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
18884 c.
x = (float)((
int)c.
x);
18885 c.
y = (float)((
int)c.
y);
18886 c.
w = (float)((
int)c.
w);
18887 c.
h = (float)((
int)c.
h);
18889 nk_layout_peek(&bounds, ctx);
18890 nk_unify(&v, &c, bounds.
x, bounds.
y, bounds.
x + bounds.
w, bounds.
y + bounds.
h);
18910 nk_panel_alloc_space(bounds, ctx);
18926 bounds->
x = (float)((
int)bounds->
x);
18927 bounds->
y = (float)((
int)bounds->
y);
18928 bounds->
w = (float)((
int)bounds->
w);
18929 bounds->
h = (float)((
int)bounds->
h);
18931 c.
x = (float)((
int)c.
x);
18932 c.
y = (float)((
int)c.
y);
18933 c.
w = (float)((
int)c.
w);
18934 c.
h = (float)((
int)c.
h);
18936 nk_unify(&v, &c, bounds->
x, bounds->
y, bounds->
x + bounds->
w, bounds->
y + bounds->
h);
18952 struct nk_vec2 panel_padding;
18961 style = &ctx->
style;
18965 panel_padding = nk_panel_get_padding(style, layout->
type);
18967 bounds->
w += panel_padding.x;
18968 bounds->
x -= panel_padding.x;
18969 }
else bounds->
x -= item_padding.
x;
18972 bounds->
w += panel_padding.x;
18973 else bounds->
w += item_padding.
x;
18982 int i, index, rows;
18996 for (i = 0; i < rows; ++i)
18997 nk_panel_alloc_row(ctx, win);
19003 for (i = 0; i < cols; ++i)
19004 nk_panel_alloc_space(&none, ctx);
19019 const char *
string,
int len,
const struct nk_text *t,
19027 if (!o || !t)
return;
19029 b.
h =
NK_MAX(b.
h, 2 * t->padding.y);
19030 label.x = 0; label.w = 0;
19031 label.y = b.
y + t->padding.y;
19035 text_width += (2.0f * t->padding.x);
19039 label.x = b.
x + t->padding.x;
19040 label.w =
NK_MAX(0, b.
w - 2 * t->padding.x);
19042 label.w =
NK_MAX(1, 2 * t->padding.x + (
float)text_width);
19043 label.x = (b.
x + t->padding.x + ((b.
w - 2 * t->padding.x) - label.w) / 2);
19044 label.x =
NK_MAX(b.
x + t->padding.x, label.x);
19045 label.w =
NK_MIN(b.
x + b.
w, label.x + label.w);
19046 if (label.w >= label.x) label.w -= label.x;
19048 label.x =
NK_MAX(b.
x + t->padding.x, (b.
x + b.
w) - (2 * t->padding.x + (
float)text_width));
19049 label.w = (float)text_width + 2 * t->padding.x;
19054 label.y = b.
y + b.
h/2.0f - (float)f->
height/2.0f;
19060 nk_draw_text(o, label, (
const char*)
string, len, f, t->background, t->text);
19064 const char *
string,
int len,
const struct nk_text *t,
19077 if (!o || !t)
return;
19080 text.background = t->background;
19081 text.text = t->text;
19083 b.
w =
NK_MAX(b.
w, 2 * t->padding.x);
19084 b.
h =
NK_MAX(b.
h, 2 * t->padding.y);
19085 b.
h = b.
h - 2 * t->padding.y;
19087 line.x = b.
x + t->padding.x;
19088 line.y = b.
y + t->padding.y;
19089 line.w = b.
w - 2 * t->padding.x;
19090 line.h = 2 * t->padding.y + f->
height;
19092 fitting = nk_text_clamp(f,
string, len, line.w, &glyphs, &width, seperator,
NK_LEN(seperator));
19093 while (done < len) {
19094 if (!fitting || line.y + line.h >= (b.
y + b.
h))
break;
19095 nk_widget_text(o, line, &
string[done], fitting, &text,
NK_TEXT_LEFT, f);
19097 line.y += f->
height + 2 * t->padding.y;
19098 fitting = nk_text_clamp(f, &
string[done], len - done, line.w, &glyphs, &width, seperator,
NK_LEN(seperator));
19118 style = &ctx->
style;
19119 nk_panel_alloc_space(&bounds, ctx);
19122 text.padding.
x = item_padding.
x;
19123 text.padding.y = item_padding.
y;
19126 nk_widget_text(&win->
buffer, bounds, str, len, &text, alignment, style->
font);
19145 style = &ctx->
style;
19146 nk_panel_alloc_space(&bounds, ctx);
19149 text.padding.
x = item_padding.
x;
19150 text.padding.y = item_padding.
y;
19153 nk_widget_text_wrap(&win->
buffer, bounds, str, len, &text, style->
font);
19155 #ifdef NK_INCLUDE_STANDARD_VARARGS 19158 struct nk_color color,
const char *fmt, ...)
19161 va_start(args, fmt);
19162 nk_labelfv_colored(ctx, flags, color, fmt, args);
19167 const char *fmt, ...)
19170 va_start(args, fmt);
19171 nk_labelfv_colored_wrap(ctx, color, fmt, args);
19178 va_start(args, fmt);
19179 nk_labelfv(ctx, flags, fmt, args);
19183 nk_labelf_wrap(
struct nk_context *ctx,
const char *fmt,...)
19186 va_start(args, fmt);
19187 nk_labelfv_wrap(ctx, fmt, args);
19192 struct nk_color color,
const char *fmt, va_list args)
19195 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19201 const char *fmt, va_list args)
19204 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19212 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19217 nk_labelfv_wrap(
struct nk_context *ctx,
const char *fmt, va_list args)
19220 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
19225 nk_value_bool(
struct nk_context *ctx,
const char *prefix,
int value)
19227 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %s", prefix, ((value) ?
"true":
"false"));
19230 nk_value_int(
struct nk_context *ctx,
const char *prefix,
int value)
19232 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %d", prefix, value);
19235 nk_value_uint(
struct nk_context *ctx,
const char *prefix,
unsigned int value)
19237 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %u", prefix, value);
19240 nk_value_float(
struct nk_context *ctx,
const char *prefix,
float value)
19242 double double_value = (double)value;
19243 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: %.3f", prefix, double_value);
19248 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: (%d, %d, %d, %d)", p, c.
r, c.
g, c.
b, c.
a);
19254 nk_labelf(ctx,
NK_TEXT_LEFT,
"%s: (%.2f, %.2f, %.2f, %.2f)",
19255 p, c[0], c[1], c[2], c[3]);
19258 nk_value_color_hex(
struct nk_context *ctx,
const char *prefix,
struct nk_color color)
19329 nk_zero(&s,
sizeof(s));
19330 s.handle.ptr = ptr;
19332 s.region[0] = (
unsigned short)r.x;
19333 s.region[1] = (
unsigned short)r.y;
19334 s.region[2] = (
unsigned short)r.w;
19335 s.region[3] = (
unsigned short)r.h;
19342 nk_zero(&s,
sizeof(s));
19345 s.region[0] = (
unsigned short)r.x;
19346 s.region[1] = (
unsigned short)r.y;
19347 s.region[2] = (
unsigned short)r.w;
19348 s.region[3] = (
unsigned short)r.h;
19356 nk_zero(&s,
sizeof(s));
19359 s.region[0] = (
unsigned short)r.x;
19360 s.region[1] = (
unsigned short)r.y;
19361 s.region[2] = (
unsigned short)r.w;
19362 s.region[3] = (
unsigned short)r.h;
19369 nk_zero(&s,
sizeof(s));
19382 nk_zero(&s,
sizeof(s));
19384 s.handle.ptr = ptr;
19396 nk_zero(&s,
sizeof(s));
19409 return !(img->
w == 0 && img->
h == 0);
19467 text.background = background;
19468 text.text = foreground;
19479 nk_fill_rect(out, nk_shrink_rect(content, border_width), 0, background);
19497 points[2].
x, points[2].
y, foreground);
19509 nk_widget_state_reset(state);
19518 #ifdef NK_BUTTON_TRIGGER_ON_RELEASE 19538 background = &style->
hover;
19540 background = &style->
active;
19541 else background = &style->
normal;
19560 if (!out || !style)
19584 background = nk_draw_button(out, bounds, state, style);
19588 text.background = background->
data.
color;
19597 nk_widget_text(out, *content, txt, len, &text, text_alignment, font);
19600 nk_do_button_text(
nk_flags *state,
19614 if (!out || !style || !font || !
string)
19617 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19619 nk_draw_button_text(out, &bounds, &content, *state, style,
string, len, align, font);
19633 background = nk_draw_button(out, bounds, state, style);
19643 nk_draw_symbol(out,
type, *content, bg, sym, 1, font);
19646 nk_do_button_symbol(
nk_flags *state,
19659 if (!out || !style || !font || !state)
19662 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19664 nk_draw_button_symbol(out, &bounds, &content, *state, style, symbol, font);
19673 nk_draw_button(out, bounds, state, style);
19677 nk_do_button_image(
nk_flags *state,
19688 if (!out || !style || !state)
19691 ret = nk_do_button(state, out, bounds, style, in, b, &content);
19698 nk_draw_button_image(out, &bounds, &content, *state, style, &img);
19714 background = nk_draw_button(out, bounds, state, style);
19716 text.background = background->
data.
color;
19736 nk_do_button_text_symbol(
nk_flags *state,
19743 struct nk_rect tri = {0,0,0,0};
19749 if (!out || !style || !font)
19752 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19753 tri.
y = content.
y + (content.
h/2) - font->
height/2;
19756 tri.
x = (content.
x + content.
w) - (2 * style->
padding.
x + tri.
w);
19758 }
else tri.
x = content.
x + 2 * style->
padding.
x;
19762 nk_draw_button_text_symbol(out, &bounds, &content, &tri,
19763 *state, style, str, len, symbol, font);
19771 const char *str,
int len,
const struct nk_user_font *font,
19776 background = nk_draw_button(out, bounds, state, style);
19780 text.background = background->
data.
color;
19793 nk_do_button_text_image(
nk_flags *state,
19807 if (!out || !font || !style || !str)
19810 ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
19812 icon.w = icon.h = bounds.
h - 2 * style->
padding.
y;
19814 icon.x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.w);
19815 icon.x =
NK_MAX(icon.x, 0);
19816 }
else icon.x = bounds.
x + 2 * style->
padding.
x;
19824 nk_draw_button_text_image(out, &bounds, &content, &icon, *state, style, str, len, font, &img);
19838 struct nk_config_stack_button_behavior *button_stack;
19839 struct nk_config_stack_button_behavior_element *element;
19842 if (!ctx)
return 0;
19845 NK_ASSERT(button_stack->head < (
int)
NK_LEN(button_stack->elements));
19846 if (button_stack->head >= (
int)
NK_LEN(button_stack->elements))
19849 element = &button_stack->elements[button_stack->head++];
19858 struct nk_config_stack_button_behavior *button_stack;
19859 struct nk_config_stack_button_behavior_element *element;
19862 if (!ctx)
return 0;
19865 NK_ASSERT(button_stack->head > 0);
19866 if (button_stack->head < 1)
19869 element = &button_stack->elements[--button_stack->head];
19870 *element->address = element->old_value;
19894 if (!state)
return 0;
19904 if (!ctx)
return 0;
19939 if (!state)
return 0;
19971 if (!state)
return 0;
19980 if (!ctx)
return 0;
20004 if (!state)
return 0;
20013 if (!ctx)
return 0;
20019 const char *text,
int len,
nk_flags align)
20038 if (!state)
return 0;
20046 const char* text,
int len,
nk_flags align)
20049 if (!ctx)
return 0;
20053 const char *label,
nk_flags align)
20059 const char *title,
nk_flags align)
20085 if (!state)
return 0;
20093 const char *text,
int len,
nk_flags align)
20098 const char *label,
nk_flags align)
20104 const char *label,
nk_flags text_alignment)
20122 nk_widget_state_reset(state);
20137 const struct nk_rect *cursors,
const char *
string,
int len,
20146 background = &style->
hover;
20150 background = &style->
hover;
20154 background = &style->
normal;
20170 text.padding.x = 0;
20171 text.padding.y = 0;
20173 nk_widget_text(out, *label,
string, len, &text,
NK_TEXT_LEFT, font);
20179 const struct nk_rect *cursors,
const char *
string,
int len,
20188 background = &style->
hover;
20192 background = &style->
hover;
20196 background = &style->
normal;
20212 text.padding.x = 0;
20213 text.padding.y = 0;
20215 nk_widget_text(out, *label,
string, len, &text,
NK_TEXT_LEFT, font);
20220 int *active,
const char *str,
int len,
enum nk_toggle_type type,
20233 if (!out || !style || !font || !active)
20247 select.
h = select.
w;
20248 select.
y = r.
y + r.
h/2.0f - select.
h/2.0f;
20258 label.
x = select.
x + select.
w + style->
spacing;
20259 label.
y = select.
y;
20261 label.
h = select.
w;
20264 was_active = *active;
20265 *active = nk_toggle_behavior(in, bounds, state, *active);
20270 if (type == NK_TOGGLE_CHECK) {
20271 nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font);
20273 nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font);
20277 return (was_active != *active);
20302 style = &ctx->
style;
20306 if (!state)
return active;
20309 text, len, NK_TOGGLE_CHECK, &style->
checkbox, in, style->
font);
20314 unsigned int flags,
unsigned int value)
20319 if (!ctx || !text)
return flags;
20320 old_active = (int)((flags & value) & value);
20323 else flags &= ~value;
20333 if (!ctx || !text || !active)
return 0;
20336 return old_val != *active;
20340 unsigned int *flags,
unsigned int value)
20346 if (!ctx || !text || !flags)
return 0;
20348 active = (int)((*flags & value) & value);
20350 if (active) *flags |= value;
20351 else *flags &= ~value;
20361 unsigned int flags,
unsigned int value)
20370 unsigned int *flags,
unsigned int value)
20397 style = &ctx->
style;
20401 if (!state)
return (
int)state;
20404 text, len, NK_TOGGLE_OPTION, &style->
option, in, style->
font);
20414 if (!ctx || !text || !active)
return 0;
20415 old_value = *active;
20417 return old_value != *active;
20442 const struct nk_rect *bounds,
20448 text.padding = style->
padding;
20453 background = &style->
pressed;
20456 background = &style->
hover;
20459 background = &style->
normal;
20477 text.background =
nk_rgba(0,0,0,0);
20480 text.background = background->
data.
color;
20484 else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font);
20486 nk_widget_text(out, *bounds,
string, len, &text, align, font);
20490 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20505 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20506 old_value = *value;
20516 *value = !(*value);
20520 nk_draw_selectable(out, *state, style, *value, &bounds, 0,0,
NK_SYMBOL_NONE, str, len, align, font);
20522 return old_value != *value;
20526 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20542 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20543 old_value = *value;
20551 *value = !(*value);
20554 icon.
w = icon.
h = bounds.
h - 2 * style->
padding.
y;
20556 icon.
x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.
w);
20558 }
else icon.
x = bounds.
x + 2 * style->
padding.
x;
20567 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, img,
NK_SYMBOL_NONE, str, len, align, font);
20569 return old_value != *value;
20573 struct nk_rect bounds,
const char *str,
int len,
nk_flags align,
int *value,
20589 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
20590 old_value = *value;
20598 *value = !(*value);
20601 icon.
w = icon.
h = bounds.
h - 2 * style->
padding.
y;
20603 icon.
x = (bounds.
x + bounds.
w) - (2 * style->
padding.
x + icon.
w);
20605 }
else icon.
x = bounds.
x + 2 * style->
padding.
x;
20614 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, 0, sym, str, len, align, font);
20616 return old_value != *value;
20640 style = &ctx->
style;
20643 if (!state)
return 0;
20650 const char *str,
int len,
nk_flags align,
int *value)
20669 style = &ctx->
style;
20672 if (!state)
return 0;
20675 str, len, align, value, &img, &style->
selectable, in, style->
font);
20679 const char *str,
int len,
nk_flags align,
int *value)
20698 style = &ctx->
style;
20701 if (!state)
return 0;
20704 str, len, align, value, sym, &style->
selectable, in, style->
font);
20708 const char *title,
nk_flags align,
int *value)
20722 const char *str,
nk_flags align,
int *value)
20731 const char *str,
nk_flags align,
int value)
20736 const char *str,
int len,
nk_flags align,
int value)
20742 const char *title,
int title_len,
nk_flags align,
int value)
20748 const char *title,
nk_flags align,
int value)
20765 struct nk_rect bounds,
float slider_min,
float slider_max,
float slider_value,
20766 float slider_step,
float slider_steps)
20768 int left_mouse_down;
20769 int left_mouse_click_in_cursor;
20772 nk_widget_state_reset(state);
20777 if (left_mouse_down && left_mouse_click_in_cursor) {
20779 const float d = in->
mouse.
pos.
x - (visual_cursor->
x+visual_cursor->
w*0.5f);
20780 const float pxstep = bounds.
w / slider_steps;
20784 if (
NK_ABS(d) >= pxstep) {
20785 const float steps = (float)((
int)(
NK_ABS(d) / pxstep));
20786 slider_value += (d > 0) ? (slider_step*steps) : -(slider_step*steps);
20787 slider_value =
NK_CLAMP(slider_min, slider_value, slider_max);
20788 ratio = (slider_value - slider_min)/slider_step;
20789 logical_cursor->
x = bounds.
x + (logical_cursor->
w * ratio);
20802 return slider_value;
20807 const struct nk_rect *visual_cursor,
float min,
float value,
float max)
20822 background = &style->
active;
20826 background = &style->
hover;
20830 background = &style->
normal;
20836 bar.y = (visual_cursor->
y + visual_cursor->
h/2) - bounds->
h/12;
20838 bar.h = bounds->
h/6;
20841 fill.w = (visual_cursor->
x + (visual_cursor->
w/2.0f)) - bar.x;
20866 float min,
float val,
float max,
float step,
20870 float slider_range;
20873 float slider_value;
20874 float slider_steps;
20875 float cursor_offset;
20877 struct nk_rect visual_cursor;
20878 struct nk_rect logical_cursor;
20882 if (!out || !style)
20897 button.y = bounds.
y;
20898 button.w = bounds.
h;
20899 button.h = bounds.
h;
20902 button.x = bounds.
x;
20908 button.x = (bounds.
x + bounds.
w) - button.w;
20913 bounds.
x = bounds.
x + button.w + style->
spacing.
x;
20914 bounds.
w = bounds.
w - (2*button.w + 2*style->
spacing.
x);
20922 slider_max =
NK_MAX(min, max);
20923 slider_min =
NK_MIN(min, max);
20924 slider_value =
NK_CLAMP(slider_min, val, slider_max);
20925 slider_range = slider_max - slider_min;
20926 slider_steps = slider_range / step;
20927 cursor_offset = (slider_value - slider_min) / step;
20932 logical_cursor.
h = bounds.
h;
20933 logical_cursor.
w = bounds.
w / slider_steps;
20934 logical_cursor.
x = bounds.
x + (logical_cursor.
w * cursor_offset);
20935 logical_cursor.
y = bounds.
y;
20939 visual_cursor.
y = (bounds.
y + bounds.
h*0.5f) - visual_cursor.
h*0.5f;
20940 visual_cursor.
x = logical_cursor.
x - visual_cursor.
w*0.5f;
20942 slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor,
20943 in, bounds, slider_min, slider_max, slider_value, step, slider_steps);
20944 visual_cursor.
x = logical_cursor.
x - visual_cursor.
w*0.5f;
20948 nk_draw_slider(out, *state, style, &bounds, &visual_cursor, slider_min, slider_value, slider_max);
20950 return slider_value;
20974 style = &ctx->
style;
20978 if (!state)
return ret;
20981 old_value = *value;
20983 old_value, max_value, value_step, &style->
slider, in, style->
font);
20984 return (old_value > *value || old_value < *value);
20994 float value = (float)val;
21002 float value = (float)*val;
21003 ret =
nk_slider_float(ctx, (
float)min, &value, (
float)max, (
float)step);
21021 int left_mouse_down = 0;
21022 int left_mouse_click_in_cursor = 0;
21024 nk_widget_state_reset(state);
21025 if (!in || !modifiable)
return value;
21032 if (in && left_mouse_down && left_mouse_click_in_cursor) {
21033 if (left_mouse_down && left_mouse_click_in_cursor) {
21034 float ratio =
NK_MAX(0, (
float)(in->
mouse.
pos.
x - cursor.
x)) / (float)cursor.
w;
21060 background = &style->
active;
21063 background = &style->
hover;
21066 background = &style->
normal;
21094 if (!out || !style)
return 0;
21100 prog_scale = (float)value / (
float)max;
21103 prog_value =
NK_MIN(value, max);
21104 prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable);
21105 cursor.w = cursor.w * prog_scale;
21109 nk_draw_progress(out, *state, style, &bounds, &cursor, value, max);
21133 style = &ctx->
style;
21136 if (!state)
return 0;
21141 *cur, max, is_modifyable, &style->
progress, in);
21142 return (*cur != old_value);
21162 int has_scrolling,
const struct nk_rect *scroll,
21164 const struct nk_rect *empty1,
float scroll_offset,
21168 int left_mouse_down;
21169 int left_mouse_click_in_cursor;
21170 float scroll_delta;
21172 nk_widget_state_reset(state);
21173 if (!in)
return scroll_offset;
21182 if (left_mouse_down && left_mouse_click_in_cursor) {
21184 float pixel, delta;
21189 delta = (pixel / scroll->
h) * target;
21190 scroll_offset =
NK_CLAMP(0, scroll_offset + delta, target - scroll->
h);
21191 cursor_y = scroll->
y + ((scroll_offset/target) * scroll->
h);
21196 delta = (pixel / scroll->
w) * target;
21197 scroll_offset =
NK_CLAMP(0, scroll_offset + delta, target - scroll->
w);
21198 cursor_x = scroll->
x + ((scroll_offset/target) * scroll->
w);
21205 scroll_offset =
NK_MAX(0, scroll_offset - scroll->
h);
21206 else scroll_offset =
NK_MAX(0, scroll_offset - scroll->
w);
21211 scroll_offset =
NK_MIN(scroll_offset + scroll->
h, target - scroll->
h);
21212 else scroll_offset =
NK_MIN(scroll_offset + scroll->
w, target - scroll->
w);
21213 }
else if (has_scrolling) {
21214 if ((scroll_delta < 0 || (scroll_delta > 0))) {
21216 scroll_offset = scroll_offset + scroll_step * (-scroll_delta);
21218 scroll_offset =
NK_CLAMP(0, scroll_offset, target - scroll->
h);
21219 else scroll_offset =
NK_CLAMP(0, scroll_offset, target - scroll->
w);
21225 if (o ==
NK_VERTICAL) scroll_offset = target - scroll->
h;
21232 return scroll_offset;
21237 const struct nk_rect *scroll)
21244 background = &style->
active;
21247 background = &style->
hover;
21250 background = &style->
normal;
21271 float offset,
float target,
float step,
float button_pixel_inc,
21280 float scroll_offset;
21282 float scroll_ratio;
21287 if (!out || !style)
return 0;
21291 if (target <= scroll.
h)
return 0;
21299 button.x = scroll.
x;
21300 button.w = scroll.
w;
21301 button.h = scroll.
w;
21303 scroll_h =
NK_MAX(scroll.
h - 2 * button.h,0);
21304 scroll_step =
NK_MIN(step, button_pixel_inc);
21307 button.y = scroll.
y;
21308 if (nk_do_button_symbol(&ws, out, button, style->
dec_symbol,
21310 offset = offset - scroll_step;
21313 button.y = scroll.
y + scroll.
h - button.h;
21314 if (nk_do_button_symbol(&ws, out, button, style->
inc_symbol,
21316 offset = offset + scroll_step;
21318 scroll.
y = scroll.
y + button.h;
21319 scroll.
h = scroll_h;
21323 scroll_step =
NK_MIN(step, scroll.
h);
21324 scroll_offset =
NK_CLAMP(0, offset, target - scroll.
h);
21325 scroll_ratio = scroll.
h / target;
21326 scroll_off = scroll_offset / target;
21330 cursor.y = scroll.
y + (scroll_off * scroll.
h) + style->
border + style->
padding.
y;
21335 empty_north.x = scroll.
x;
21336 empty_north.y = scroll.
y;
21337 empty_north.w = scroll.
w;
21338 empty_north.h =
NK_MAX(cursor.y - scroll.
y, 0);
21340 empty_south.x = scroll.
x;
21341 empty_south.y = cursor.y + cursor.h;
21342 empty_south.w = scroll.
w;
21343 empty_south.h =
NK_MAX((scroll.
y + scroll.
h) - (cursor.y + cursor.h), 0);
21346 scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor,
21347 &empty_north, &empty_south, scroll_offset, target, scroll_step,
NK_VERTICAL);
21348 scroll_off = scroll_offset / target;
21353 nk_draw_scrollbar(out, *state, style, &scroll, &cursor);
21355 return scroll_offset;
21360 float offset,
float target,
float step,
float button_pixel_inc,
21369 float scroll_offset;
21371 float scroll_ratio;
21375 if (!out || !style)
return 0;
21379 scroll.
w =
NK_MAX(scroll.
w, 2 * scroll.
h);
21380 if (target <= scroll.
w)
return 0;
21387 button.y = scroll.
y;
21388 button.w = scroll.
h;
21389 button.h = scroll.
h;
21391 scroll_w = scroll.
w - 2 * button.w;
21392 scroll_step =
NK_MIN(step, button_pixel_inc);
21395 button.x = scroll.
x;
21396 if (nk_do_button_symbol(&ws, out, button, style->
dec_symbol,
21398 offset = offset - scroll_step;
21401 button.x = scroll.
x + scroll.
w - button.w;
21402 if (nk_do_button_symbol(&ws, out, button, style->
inc_symbol,
21404 offset = offset + scroll_step;
21406 scroll.
x = scroll.
x + button.w;
21407 scroll.
w = scroll_w;
21411 scroll_step =
NK_MIN(step, scroll.
w);
21412 scroll_offset =
NK_CLAMP(0, offset, target - scroll.
w);
21413 scroll_ratio = scroll.
w / target;
21414 scroll_off = scroll_offset / target;
21417 cursor.w = (scroll_ratio * scroll.
w) - (2*style->
border + 2*style->
padding.
x);
21418 cursor.x = scroll.
x + (scroll_off * scroll.
w) + style->
border + style->
padding.
x;
21423 empty_west.x = scroll.
x;
21424 empty_west.y = scroll.
y;
21425 empty_west.w = cursor.x - scroll.
x;
21426 empty_west.h = scroll.
h;
21428 empty_east.x = cursor.x + cursor.w;
21429 empty_east.y = scroll.
y;
21430 empty_east.w = (scroll.
x + scroll.
w) - (cursor.x + cursor.w);
21431 empty_east.h = scroll.
h;
21434 scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor,
21435 &empty_west, &empty_east, scroll_offset, target, scroll_step,
NK_HORIZONTAL);
21436 scroll_off = scroll_offset / target;
21437 cursor.x = scroll.
x + (scroll_off * scroll.
w);
21441 nk_draw_scrollbar(out, *state, style, &scroll, &cursor);
21443 return scroll_offset;
21456 struct nk_text_find {
21459 int first_char, length;
21463 struct nk_text_edit_row {
21466 float baseline_y_delta;
21477 #define NK_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end) 21480 nk_textedit_get_width(
const struct nk_text_edit *edit,
int line_start,
int char_id,
21489 nk_textedit_layout_row(
struct nk_text_edit_row *r,
struct nk_text_edit *edit,
21490 int line_start_id,
float row_height,
const struct nk_user_font *font)
21495 const char *remaining;
21499 const struct nk_vec2 size = nk_text_calculate_text_bounds(font,
21500 text, (
int)(end - text), row_height, &remaining, 0, &glyphs, NK_STOP_ON_NEW_LINE);
21504 r->baseline_y_delta = size.
y;
21507 r->num_chars = glyphs;
21510 nk_textedit_locate_coord(
struct nk_text_edit *edit,
float x,
float y,
21513 struct nk_text_edit_row r;
21515 float base_y = 0, prev_x;
21519 r.ymin = r.ymax = 0;
21524 nk_textedit_layout_row(&r, edit, i, row_height, font);
21525 if (r.num_chars <= 0)
21528 if (i==0 && y < base_y + r.ymin)
21531 if (y < base_y + r.ymax)
21535 base_y += r.baseline_y_delta;
21551 for (i=0; i < r.num_chars; ++i) {
21552 float w = nk_textedit_get_width(edit, k, i, font);
21553 if (x < prev_x+w) {
21554 if (x < prev_x+w/2)
21566 return i+r.num_chars-1;
21567 else return i+r.num_chars;
21570 nk_textedit_click(
struct nk_text_edit *state,
float x,
float y,
21575 state->
cursor = nk_textedit_locate_coord(state, x, y, font, row_height);
21581 nk_textedit_drag(
struct nk_text_edit *state,
float x,
float y,
21586 int p = nk_textedit_locate_coord(state, x, y, font, row_height);
21592 nk_textedit_find_charpos(
struct nk_text_find *find,
struct nk_text_edit *state,
21593 int n,
int single_line,
const struct nk_user_font *font,
float row_height)
21597 struct nk_text_edit_row r;
21598 int prev_start = 0;
21606 nk_textedit_layout_row(&r, state, 0, row_height, font);
21608 find->first_char = 0;
21614 nk_textedit_layout_row(&r, state, i, row_height, font);
21617 find->first_char = i;
21618 find->length = r.num_chars;
21622 find->height = r.ymax - r.ymin;
21623 find->prev_first = prev_start;
21631 nk_textedit_layout_row(&r, state, i, row_height, font);
21632 if (n < i + r.num_chars)
break;
21635 find->y += r.baseline_y_delta;
21638 find->first_char = first = i;
21639 find->length = r.num_chars;
21640 find->height = r.ymax - r.ymin;
21641 find->prev_first = prev_start;
21645 for (i=0; first+i < n; ++i)
21646 find->x += nk_textedit_get_width(state, first, i, font);
21653 if (NK_TEXT_HAS_SELECTION(state)) {
21666 nk_textedit_makeundo_delete(state, where, len);
21674 nk_textedit_clamp(state);
21675 if (NK_TEXT_HAS_SELECTION(state)) {
21702 if (NK_TEXT_HAS_SELECTION(state)) {
21703 nk_textedit_sortselection(state);
21713 if (NK_TEXT_HAS_SELECTION(state)) {
21714 nk_textedit_sortselection(state);
21715 nk_textedit_clamp(state);
21722 nk_is_word_boundary(
struct nk_text_edit *state,
int idx)
21726 if (idx <= 0)
return 1;
21728 return (c ==
' ' || c ==
'\t' ||c == 0x3000 || c ==
',' || c ==
';' ||
21729 c ==
'(' || c ==
')' || c ==
'{' || c ==
'}' || c ==
'[' || c ==
']' ||
21733 nk_textedit_move_to_word_previous(
struct nk_text_edit *state)
21735 int c = state->
cursor - 1;
21736 while( c >= 0 && !nk_is_word_boundary(state, c))
21745 nk_textedit_move_to_word_next(
struct nk_text_edit *state)
21748 int c = state->
cursor+1;
21749 while( c < len && !nk_is_word_boundary(state, c))
21758 nk_textedit_prep_selection_at_cursor(
struct nk_text_edit *state)
21761 if (!NK_TEXT_HAS_SELECTION(state))
21771 if (NK_TEXT_HAS_SELECTION(state)) {
21783 const char *text = (
const char *) ctext;
21787 nk_textedit_clamp(state);
21793 nk_textedit_makeundo_insert(state, state->
cursor, glyphs);
21815 while ((text_len < total_len) && glyph_len)
21818 if (unicode == 127)
goto next;
21820 if (unicode ==
'\n' && state->
single_line)
goto next;
21822 if (state->
filter && !state->
filter(state, unicode))
goto next;
21824 if (!NK_TEXT_HAS_SELECTION(state) &&
21828 nk_textedit_makeundo_replace(state, state->
cursor, 1, 1);
21842 nk_textedit_makeundo_insert(state, state->
cursor, 1);
21848 text_len += glyph_len;
21849 glyph_len =
nk_utf_decode(text + text_len, &unicode, total_len-text_len);
21900 nk_textedit_clamp(state);
21901 nk_textedit_prep_selection_at_cursor(state);
21910 if (NK_TEXT_HAS_SELECTION(state))
21911 nk_textedit_move_to_first(state);
21912 else if (state->
cursor > 0)
21919 nk_textedit_prep_selection_at_cursor(state);
21922 nk_textedit_clamp(state);
21928 if (NK_TEXT_HAS_SELECTION(state))
21929 nk_textedit_move_to_last(state);
21931 nk_textedit_clamp(state);
21937 if( !NK_TEXT_HAS_SELECTION( state ) )
21938 nk_textedit_prep_selection_at_cursor(state);
21939 state->
cursor = nk_textedit_move_to_word_previous(state);
21941 nk_textedit_clamp(state );
21943 if (NK_TEXT_HAS_SELECTION(state))
21944 nk_textedit_move_to_first(state);
21946 state->
cursor = nk_textedit_move_to_word_previous(state);
21947 nk_textedit_clamp(state );
21953 if( !NK_TEXT_HAS_SELECTION( state ) )
21954 nk_textedit_prep_selection_at_cursor(state);
21955 state->
cursor = nk_textedit_move_to_word_next(state);
21957 nk_textedit_clamp(state);
21959 if (NK_TEXT_HAS_SELECTION(state))
21960 nk_textedit_move_to_last(state);
21962 state->
cursor = nk_textedit_move_to_word_next(state);
21963 nk_textedit_clamp(state );
21968 struct nk_text_find find;
21969 struct nk_text_edit_row row;
21970 int i, sel = shift_mod;
21979 nk_textedit_prep_selection_at_cursor(state);
21980 else if (NK_TEXT_HAS_SELECTION(state))
21981 nk_textedit_move_to_last(state);
21984 nk_textedit_clamp(state);
21993 int start = find.first_char + find.length;
21996 nk_textedit_layout_row(&row, state, state->
cursor, row_height, font);
21999 for (i=0; i < row.num_chars && x < row.x1; ++i) {
22000 float dx = nk_textedit_get_width(state, start, i, font);
22006 nk_textedit_clamp(state);
22016 struct nk_text_find find;
22017 struct nk_text_edit_row row;
22018 int i, sel = shift_mod;
22027 nk_textedit_prep_selection_at_cursor(state);
22028 else if (NK_TEXT_HAS_SELECTION(state))
22029 nk_textedit_move_to_first(state);
22032 nk_textedit_clamp(state);
22037 if (find.prev_first != find.first_char) {
22042 state->
cursor = find.prev_first;
22043 nk_textedit_layout_row(&row, state, state->
cursor, row_height, font);
22046 for (i=0; i < row.num_chars && x < row.x1; ++i) {
22047 float dx = nk_textedit_get_width(state, find.prev_first, i, font);
22053 nk_textedit_clamp(state);
22064 if (NK_TEXT_HAS_SELECTION(state))
22077 if (NK_TEXT_HAS_SELECTION(state))
22080 nk_textedit_clamp(state);
22081 if (state->
cursor > 0) {
22091 nk_textedit_prep_selection_at_cursor(state);
22102 nk_textedit_prep_selection_at_cursor(state);
22114 struct nk_text_find find;
22115 nk_textedit_clamp(state);
22116 nk_textedit_prep_selection_at_cursor(state);
22124 struct nk_text_find find;
22127 nk_textedit_clamp(state);
22128 nk_textedit_move_to_first(state);
22131 state->
cursor = find.first_char;
22138 struct nk_text_find find;
22139 nk_textedit_clamp(state);
22140 nk_textedit_prep_selection_at_cursor(state);
22144 state->
cursor = find.first_char + find.length;
22149 struct nk_text_find find;
22150 nk_textedit_clamp(state);
22151 nk_textedit_move_to_first(state);
22156 state->
cursor = find.first_char + find.length;
22226 nk_textedit_flush_redo(state);
22231 nk_textedit_discard_undo(state);
22244 nk_textedit_discard_undo(state);
22249 int insert_len,
int delete_len)
22259 if (insert_len == 0) {
22283 r->
where = u.where;
22285 if (u.delete_length)
22304 nk_textedit_discard_redo(s);
22315 for (i=0; i < u.delete_length; ++i)
22324 if (u.insert_length) {
22327 &s->
undo_char[u.char_storage], u.insert_length);
22330 state->
cursor = (short)(u.where + u.insert_length);
22387 nk_textedit_createundo(&state->
undo,
where, 0, length);
22395 for (i=0; i < length; ++i)
22401 int old_length,
int new_length)
22404 nk_rune *p = nk_textedit_createundo(&state->
undo,
where, old_length, new_length);
22406 for (i=0; i < old_length; ++i)
22435 if (!state || !memory || !size)
return;
22445 if (!state || !alloc)
return;
22450 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR 22455 if (!state)
return;
22458 nk_str_init_default(&state->
string);
22472 if (!state)
return;
22496 if (unicode > 128)
return nk_false;
22503 if ((unicode < '0' || unicode >
'9') && unicode !=
'.' && unicode !=
'-')
22511 if ((unicode < '0' || unicode >
'9') && unicode !=
'-')
22519 if ((unicode < '0' || unicode >
'9') &&
22520 (unicode < 'a' || unicode >
'f') &&
22521 (unicode < 'A' || unicode >
'F'))
22529 if (unicode < '0' || unicode >
'7')
22537 if (unicode !=
'0' && unicode !=
'1')
22549 const struct nk_style_edit *style,
float pos_x,
float pos_y,
22550 float x_offset,
const char *text,
int byte_len,
float row_height,
22552 struct nk_color foreground,
int is_selected)
22557 if (!text || !byte_len || !out || !style)
return;
22559 {
int glyph_len = 0;
22562 float line_width = 0;
22564 const char *line = text;
22565 float line_offset = 0;
22566 int line_count = 0;
22570 txt.background = background;
22571 txt.text = foreground;
22573 glyph_len =
nk_utf_decode(text+text_len, &unicode, byte_len-text_len);
22574 if (!glyph_len)
return;
22575 while ((text_len < byte_len) && glyph_len)
22577 if (unicode ==
'\n') {
22580 label.
y = pos_y + line_offset;
22581 label.h = row_height;
22582 label.w = line_width;
22585 label.x += x_offset;
22589 nk_widget_text(out, label, line, (
int)((text + text_len) - line),
22595 line = text + text_len;
22596 line_offset += row_height;
22597 glyph_len =
nk_utf_decode(text + text_len, &unicode, (
int)(byte_len-text_len));
22600 if (unicode ==
'\r') {
22602 glyph_len =
nk_utf_decode(text + text_len, &unicode, byte_len-text_len);
22606 line_width += (float)glyph_width;
22607 text_len += glyph_len;
22608 glyph_len =
nk_utf_decode(text + text_len, &unicode, byte_len-text_len);
22611 if (line_width > 0) {
22614 label.
y = pos_y + line_offset;
22615 label.h = row_height;
22616 label.w = line_width;
22619 label.x += x_offset;
22623 nk_widget_text(out, label, line, (
int)((text + text_len) - line),
22636 char prev_state = 0;
22637 char is_hovered = 0;
22638 char select_all = 0;
22639 char cursor_follow = 0;
22646 if (!state || !out || !style)
22659 old_clip = out->
clip;
22660 nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h);
22663 prev_state = (char)edit->
active;
22667 bounds.
x, bounds.
y, bounds.
w, bounds.
h);
22671 if (!prev_state && edit->
active) {
22674 nk_textedit_clear_state(edit, type, filter);
22688 if (prev_state != edit->
active)
22704 nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
22707 nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
22717 int old_mode = edit->
mode;
22721 nk_textedit_key(edit, (
enum nk_keys)i, shift_mod, font, row_height);
22725 if (old_mode != edit->
mode) {
22758 int begin =
NK_MIN(b, e);
22787 else nk_widget_state_reset(state);
22799 background = &style->
active;
22801 background = &style->
hover;
22802 else background = &style->
normal;
22813 int total_lines = 1;
22817 const char *cursor_ptr = 0;
22818 const char *select_begin_ptr = 0;
22819 const char *select_end_ptr = 0;
22830 float line_width = 0.0f;
22846 while ((text_len < len) && glyph_len)
22849 if (!cursor_ptr && glyphs == edit->
cursor)
22854 const char *remaining;
22857 cursor_pos.
y = (float)(total_lines-1) * row_height;
22858 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
22859 text_len-row_begin, row_height, &remaining,
22860 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
22861 cursor_pos.
x = row_size.x;
22862 cursor_ptr = text + text_len;
22867 glyphs == selection_begin)
22872 const char *remaining;
22875 selection_offset_start.
y = (float)(
NK_MAX(total_lines-1,0)) * row_height;
22876 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
22877 text_len-row_begin, row_height, &remaining,
22878 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
22879 selection_offset_start.
x = row_size.x;
22880 select_begin_ptr = text + text_len;
22885 glyphs == selection_end)
22890 const char *remaining;
22893 selection_offset_end.
y = (float)(total_lines-1) * row_height;
22894 row_size = nk_text_calculate_text_bounds(font, text+row_begin,
22895 text_len-row_begin, row_height, &remaining,
22896 &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
22897 selection_offset_end.
x = row_size.x;
22898 select_end_ptr = text + text_len;
22900 if (unicode ==
'\n') {
22901 text_size.
x =
NK_MAX(text_size.
x, line_width);
22906 row_begin = text_len;
22907 glyph_len =
nk_utf_decode(text + text_len, &unicode, len-text_len);
22913 text_len += glyph_len;
22914 line_width += (float)glyph_width;
22916 glyph_len =
nk_utf_decode(text + text_len, &unicode, len-text_len);
22918 text+text_len, glyph_len);
22921 text_size.
y = (float)total_lines * row_height;
22925 cursor_pos.
x = line_width;
22926 cursor_pos.
y = text_size.
y - row_height;
22936 const float scroll_increment = area.w * 0.25f;
22957 float scroll_target;
22958 float scroll_offset;
22967 scroll_step = scroll.
h * 0.10f;
22968 scroll_inc = scroll.
h * 0.01f;
22969 scroll_target = text_size.
y;
22970 edit->
scrollbar.
y = nk_do_scrollbarv(&ws, out, scroll, 0,
22971 scroll_offset, scroll_target, scroll_step, scroll_inc,
22977 {
struct nk_color background_color;
22979 struct nk_color sel_background_color;
22982 struct nk_color cursor_text_color;
22988 background = &style->
active;
22995 background = &style->
hover;
23002 background = &style->
normal;
23010 background_color =
nk_rgba(0,0,0,0);
23011 else background_color = background->
data.
color;
23018 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23019 area.y - edit->
scrollbar.
y, 0, begin, l, row_height, font,
23020 background_color, text_color,
nk_false);
23026 NK_ASSERT(select_begin_ptr);
23027 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23028 area.y - edit->
scrollbar.
y, 0, begin, (
int)(select_begin_ptr - begin),
23029 row_height, font, background_color, text_color,
nk_false);
23033 NK_ASSERT(select_begin_ptr);
23034 if (!select_end_ptr) {
23038 nk_edit_draw_text(out, style,
23040 area.y + selection_offset_start.
y - edit->
scrollbar.
y,
23041 selection_offset_start.
x,
23042 select_begin_ptr, (
int)(select_end_ptr - select_begin_ptr),
23043 row_height, font, sel_background_color, sel_text_color,
nk_true);
23046 selection_end < edit->
string.len))
23049 const char *begin = select_end_ptr;
23052 NK_ASSERT(select_end_ptr);
23053 nk_edit_draw_text(out, style,
23055 area.y + selection_offset_end.
y - edit->
scrollbar.
y,
23056 selection_offset_end.
x,
23057 begin, (
int)(end - begin), row_height, font,
23058 background_color, text_color,
nk_true);
23066 (cursor_ptr && *cursor_ptr ==
'\n')) {
23070 cursor.h = font->
height;
23071 cursor.x = area.x + cursor_pos.
x - edit->
scrollbar.
x;
23072 cursor.y = area.y + cursor_pos.
y + row_height/2.0f - cursor.h/2.0f;
23082 NK_ASSERT(cursor_ptr);
23085 label.x = area.x + cursor_pos.
x - edit->
scrollbar.
x;
23086 label.y = area.y + cursor_pos.
y - edit->
scrollbar.
y;
23088 label.h = row_height;
23091 txt.background = cursor_color;;
23092 txt.text = cursor_text_color;
23094 nk_widget_text(out, label, cursor_ptr, glyph_len, &txt,
NK_TEXT_LEFT, font);
23107 background = &style->
active;
23110 background = &style->
hover;
23113 background = &style->
normal;
23117 background_color =
nk_rgba(0,0,0,0);
23118 else background_color = background->
data.
color;
23119 nk_edit_draw_text(out, style, area.x - edit->
scrollbar.
x,
23120 area.y - edit->
scrollbar.
y, 0, begin, l, row_height, font,
23121 background_color, text_color,
nk_false);
23134 if (!ctx || !ctx->
current)
return;
23149 if (!ctx || !ctx->
current)
return;
23167 if (!ctx || !memory || !len)
23195 *len =
NK_MIN(*len, max-1);
23200 *len = (int)
edit->string.buffer.allocated;
23223 unsigned char prev_state;
23235 style = &ctx->
style;
23237 if (!state)
return state;
23256 prev_state = (
unsigned char)edit->
active;
23259 filter, edit, &style->
edit, in, style->
font);
23267 }
else if (prev_state && !edit->
active) {
23270 }
return ret_flags;
23294 struct nk_rect drag,
struct nk_property_variant *variant,
23295 float inc_per_pixel)
23298 int left_mouse_click_in_cursor = in &&
23301 nk_widget_state_reset(state);
23305 if (left_mouse_down && left_mouse_click_in_cursor) {
23306 float delta, pixels;
23308 delta = pixels * inc_per_pixel;
23309 switch (variant->kind) {
23311 case NK_PROPERTY_INT:
23312 variant->value.i = variant->value.i + (int)delta;
23313 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
23315 case NK_PROPERTY_FLOAT:
23316 variant->value.f = variant->value.f + (float)delta;
23317 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
23319 case NK_PROPERTY_DOUBLE:
23320 variant->value.d = variant->value.d + (double)delta;
23321 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
23334 struct nk_rect empty,
int *state,
struct nk_property_variant *variant,
23335 float inc_per_pixel)
23337 if (in && *state == NK_PROPERTY_DEFAULT) {
23339 *state = NK_PROPERTY_EDIT;
23341 *state = NK_PROPERTY_DRAG;
23343 *state = NK_PROPERTY_DRAG;
23345 if (*state == NK_PROPERTY_DRAG) {
23346 nk_drag_behavior(ws, in, property, variant, inc_per_pixel);
23353 const char *name,
int len,
const struct nk_user_font *font)
23360 background = &style->
active;
23363 background = &style->
hover;
23366 background = &style->
normal;
23373 text.background =
nk_rgba(0,0,0,0);
23375 text.background = background->
data.
color;
23387 const char *name,
struct nk_property_variant *variant,
23388 float inc_per_pixel,
char *buffer,
int *len,
23389 int *state,
int *cursor,
int *select_begin,
int *select_end,
23391 enum nk_property_filter filter,
struct nk_input *in,
23400 int num_len, name_len;
23417 left.y =
property.y + style->
border +
property.h/2.0f - left.h/2;
23422 label.
x = left.x + left.w + style->
padding.
x;
23423 label.
w = (float)size + 2 * style->
padding.
x;
23431 right.x =
property.x +
property.w - (right.w + style->
padding.
x);
23434 if (*state == NK_PROPERTY_EDIT) {
23440 switch (variant->kind) {
23442 case NK_PROPERTY_INT:
23443 nk_itoa(
string, variant->value.i);
23446 case NK_PROPERTY_FLOAT:
23447 NK_DTOA(
string, (
double)variant->value.f);
23450 case NK_PROPERTY_DOUBLE:
23451 NK_DTOA(
string, variant->value.d);
23460 edit.
w = (float)size + 2 * style->
padding.
x;
23461 edit.
w =
NK_MIN(edit.
w, right.x - (label.
x + label.
w));
23462 edit.
x = right.x - (edit.
w + style->
padding.
x);
23463 edit.
y =
property.y + style->
border;
23464 edit.
h =
property.h - (2 * style->
border);
23467 empty.
w = edit.
x - (label.
x + label.
w);
23468 empty.
x = label.
x + label.
w;
23469 empty.
y =
property.y;
23470 empty.
h =
property.h;
23473 old = (*state == NK_PROPERTY_EDIT);
23474 nk_property_behavior(ws, in, property, label, edit, empty, state, variant, inc_per_pixel);
23478 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font);
23482 if (nk_do_button_symbol(ws, out, left, style->
sym_left, behavior, &style->
dec_button, in, font)) {
23483 switch (variant->kind) {
23485 case NK_PROPERTY_INT:
23486 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i);
break;
23487 case NK_PROPERTY_FLOAT:
23488 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f);
break;
23489 case NK_PROPERTY_DOUBLE:
23490 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d);
break;
23494 if (nk_do_button_symbol(ws, out, right, style->
sym_right, behavior, &style->
inc_button, in, font)) {
23495 switch (variant->kind) {
23497 case NK_PROPERTY_INT:
23498 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i);
break;
23499 case NK_PROPERTY_FLOAT:
23500 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f);
break;
23501 case NK_PROPERTY_DOUBLE:
23502 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d);
break;
23505 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) {
23507 NK_MEMCPY(buffer, dst, (
nk_size)*length);
23513 }
else active = (*state == NK_PROPERTY_EDIT);
23517 text_edit->
active = (
unsigned char)active;
23528 filters[filter], text_edit, &style->
edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font);
23531 *cursor = text_edit->
cursor;
23537 if (active && !text_edit->
active) {
23539 *state = NK_PROPERTY_DEFAULT;
23540 buffer[*len] =
'\0';
23541 switch (variant->kind) {
23543 case NK_PROPERTY_INT:
23544 variant->value.i =
nk_strtoi(buffer, 0);
23545 variant->value.i =
NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
23547 case NK_PROPERTY_FLOAT:
23549 variant->value.f =
nk_strtof(buffer, 0);
23550 variant->value.f =
NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
23552 case NK_PROPERTY_DOUBLE:
23554 variant->value.d =
nk_strtod(buffer, 0);
23555 variant->value.d =
NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
23560 NK_LIB struct nk_property_variant
23561 nk_property_variant_int(int value, int min_value, int max_value, int step)
23563 struct nk_property_variant result;
23564 result.kind = NK_PROPERTY_INT;
23565 result.value.i = value;
23566 result.min_value.i = min_value;
23567 result.max_value.i = max_value;
23568 result.step.i = step;
23571 NK_LIB struct nk_property_variant
23572 nk_property_variant_float(float value, float min_value, float max_value, float step)
23574 struct nk_property_variant result;
23575 result.kind = NK_PROPERTY_FLOAT;
23576 result.value.f = value;
23577 result.min_value.f = min_value;
23578 result.max_value.f = max_value;
23579 result.step.f = step;
23582 NK_LIB struct nk_property_variant
23583 nk_property_variant_double(double value, double min_value, double max_value,
23586 struct nk_property_variant result;
23587 result.kind = NK_PROPERTY_DOUBLE;
23588 result.value.d = value;
23589 result.min_value.d = min_value;
23590 result.max_value.d = max_value;
23591 result.step.d = step;
23595 nk_property(
struct nk_context *ctx,
const char *name,
struct nk_property_variant *variant,
23596 float inc_per_pixel,
const enum nk_property_filter filter)
23611 int *select_begin = 0;
23612 int *select_end = 0;
23616 int dummy_state = NK_PROPERTY_DEFAULT;
23617 int dummy_length = 0;
23618 int dummy_cursor = 0;
23619 int dummy_select_begin = 0;
23620 int dummy_select_end = 0;
23630 style = &ctx->
style;
23635 if (name[0] ==
'#') {
23649 buffer = dummy_buffer;
23650 len = &dummy_length;
23651 cursor = &dummy_cursor;
23652 state = &dummy_state;
23653 select_begin = &dummy_select_begin;
23654 select_end = &dummy_select_end;
23658 old_state = *state;
23663 variant, inc_per_pixel, buffer, len, state, cursor, select_begin,
23667 if (in && *state != NK_PROPERTY_DEFAULT && !win->
property.
active) {
23677 if (*state == NK_PROPERTY_DRAG) {
23683 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) {
23684 if (old_state == NK_PROPERTY_DRAG) {
23696 int min,
int *val,
int max,
int step,
float inc_per_pixel)
23698 struct nk_property_variant variant;
23703 if (!ctx || !ctx->
current || !name || !val)
return;
23704 variant = nk_property_variant_int(*val, min, max, step);
23705 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
23706 *val = variant.value.i;
23710 float min,
float *val,
float max,
float step,
float inc_per_pixel)
23712 struct nk_property_variant variant;
23717 if (!ctx || !ctx->
current || !name || !val)
return;
23718 variant = nk_property_variant_float(*val, min, max, step);
23719 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23720 *val = variant.value.f;
23724 double min,
double *val,
double max,
double step,
float inc_per_pixel)
23726 struct nk_property_variant variant;
23731 if (!ctx || !ctx->
current || !name || !val)
return;
23732 variant = nk_property_variant_double(*val, min, max, step);
23733 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23734 *val = variant.value.d;
23738 int max,
int step,
float inc_per_pixel)
23740 struct nk_property_variant variant;
23744 if (!ctx || !ctx->
current || !name)
return val;
23745 variant = nk_property_variant_int(val, min, max, step);
23746 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
23747 val = variant.value.i;
23752 float val,
float max,
float step,
float inc_per_pixel)
23754 struct nk_property_variant variant;
23758 if (!ctx || !ctx->
current || !name)
return val;
23759 variant = nk_property_variant_float(val, min, max, step);
23760 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23761 val = variant.value.f;
23766 double val,
double max,
double step,
float inc_per_pixel)
23768 struct nk_property_variant variant;
23772 if (!ctx || !ctx->
current || !name)
return val;
23773 variant = nk_property_variant_double(val, min, max, step);
23774 nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
23775 val = variant.value.d;
23791 int count,
float min_value,
float max_value)
23799 struct nk_rect bounds = {0, 0, 0, 0};
23808 nk_zero(chart,
sizeof(*chart));
23813 config = &ctx->
style;
23815 style = &config->
chart;
23818 nk_zero(chart,
sizeof(*chart));
23832 slot->
min =
NK_MIN(min_value, max_value);
23833 slot->
max =
NK_MAX(min_value, max_value);
23849 int count,
float min_value,
float max_value)
23857 int count,
float min_value,
float max_value)
23873 slot->
min =
NK_MIN(min_value, max_value);
23874 slot->
max =
NK_MAX(min_value, max_value);
23879 int count,
float min_value,
float max_value)
23886 struct nk_chart *g,
float value,
int slot)
23901 step =
g->w / (float)
g->slots[slot].count;
23902 range =
g->slots[slot].max -
g->slots[slot].min;
23903 ratio = (value -
g->slots[slot].min) / range;
23905 if (
g->slots[slot].index == 0) {
23907 g->slots[slot].last.x =
g->x;
23908 g->slots[slot].last.y = (
g->y +
g->h) - ratio * (
float)
g->h;
23910 bounds.
x =
g->slots[slot].last.x - 2;
23911 bounds.
y =
g->slots[slot].last.y - 2;
23912 bounds.
w = bounds.
h = 4;
23914 color =
g->slots[slot].color;
23920 color =
g->slots[slot].highlight;
23923 g->slots[slot].index += 1;
23928 color =
g->slots[slot].color;
23929 cur.x =
g->x + (float)(step * (
float)
g->slots[slot].index);
23930 cur.y = (
g->y +
g->h) - (ratio * (
float)
g->h);
23931 nk_stroke_line(out,
g->slots[slot].last.x,
g->slots[slot].last.y, cur.x, cur.y, 1.0f, color);
23933 bounds.
x = cur.x - 3;
23934 bounds.
y = cur.y - 3;
23935 bounds.
w = bounds.
h = 6;
23943 color =
g->slots[slot].highlight;
23949 g->slots[slot].last.x = cur.x;
23950 g->slots[slot].last.y = cur.y;
23951 g->slots[slot].index += 1;
23956 struct nk_chart *chart,
float value,
int slot)
23965 struct nk_rect item = {0,0,0,0};
23971 float padding = (float)(chart->
slots[slot].
count-1);
23972 item.
w = (chart->
w - padding) / (
float)(chart->
slots[slot].
count);
23980 item.
y = (chart->
y + chart->
h) - chart->
h * ratio;
23983 item.
y = chart->
y + (chart->
h *
NK_ABS(ratio)) - item.
h;
23985 item.
x = chart->
x + ((float)chart->
slots[slot].
index * item.
w);
24009 NK_ASSERT(slot < ctx->current->layout->chart.slot);
24017 flags = nk_chart_push_line(ctx, win, &win->
layout->
chart, value, slot);
break;
24019 flags = nk_chart_push_column(ctx, win, &win->
layout->
chart, value, slot);
break;
24044 NK_MEMSET(chart, 0,
sizeof(*chart));
24049 int count,
int offset)
24057 if (!ctx || !values || !count)
return;
24059 min_value = values[offset];
24060 max_value = values[offset];
24061 for (i = 0; i < count; ++i) {
24062 min_value =
NK_MIN(values[i + offset], min_value);
24063 max_value =
NK_MAX(values[i + offset], max_value);
24067 for (i = 0; i < count; ++i)
24074 float(*value_getter)(
void* user,
int index),
int count,
int offset)
24081 NK_ASSERT(value_getter);
24082 if (!ctx || !value_getter || !count)
return;
24084 max_value = min_value = value_getter(userdata, offset);
24085 for (i = 0; i < count; ++i) {
24086 float value = value_getter(userdata, i + offset);
24087 min_value =
NK_MIN(value, min_value);
24088 max_value =
NK_MAX(value, max_value);
24092 for (i = 0; i < count; ++i)
24108 nk_color_picker_behavior(
nk_flags *state,
24114 int value_changed = 0;
24115 int hsv_changed = 0;
24119 NK_ASSERT(hue_bar);
24127 value_changed = hsv_changed = 1;
24132 value_changed = hsv_changed = 1;
24141 nk_widget_state_reset(state);
24146 if (value_changed) {
24147 color->
a = hsva[3];
24157 return value_changed;
24168 const float crosshair_size = 7.0f;
24176 NK_ASSERT(hue_bar);
24180 for (i = 0; i < 6; ++i) {
24182 {255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255},
24183 {0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255}
24186 nk_rect(hue_bar->
x, hue_bar->
y + (
float)i * (hue_bar->
h/6.0f) + 0.5f,
24187 hue_bar->
w, (hue_bar->
h/6.0f) + 0.5f), hue_colors[i], hue_colors[i],
24188 hue_colors[i+1], hue_colors[i+1]);
24190 line_y = (float)(
int)(hue_bar->
y + hsva[0] * matrix->
h + 0.5f);
24192 line_y, 1,
nk_rgb(255,255,255));
24197 line_y = (float)(
int)(alpha_bar->
y + (1.0f - alpha) * matrix->
h + 0.5f);
24201 line_y, 1,
nk_rgb(255,255,255));
24205 temp =
nk_hsv_f(hsva[0], 1.0f, 1.0f);
24210 {
struct nk_vec2 p;
float S = hsva[1];
float V = hsva[2];
24211 p.x = (float)(
int)(matrix->
x +
S * matrix->
w);
24212 p.y = (float)(
int)(matrix->
y + (1.0f -
V) * matrix->
h);
24213 nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white);
24214 nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white);
24215 nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white);
24216 nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);}
24219 nk_do_color_picker(
nk_flags *state,
24235 if (!out || !col || !state || !font)
24239 bounds.
x += padding.
x;
24240 bounds.
y += padding.
x;
24241 bounds.
w -= 2 * padding.
x;
24242 bounds.
h -= 2 * padding.
y;
24244 matrix.
x = bounds.
x;
24245 matrix.
y = bounds.
y;
24246 matrix.
h = bounds.
h;
24247 matrix.
w = bounds.
w - (3 * padding.
x + 2 * bar_w);
24250 hue_bar.
y = bounds.
y;
24251 hue_bar.
h = matrix.
h;
24252 hue_bar.
x = matrix.
x + matrix.
w + padding.
x;
24254 alpha_bar.
x = hue_bar.
x + hue_bar.
w + padding.
x;
24255 alpha_bar.
y = bounds.
y;
24256 alpha_bar.
w = bar_w;
24257 alpha_bar.
h = matrix.
h;
24259 ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar,
24260 (fmt ==
NK_RGBA) ? &alpha_bar:0, col, in);
24261 nk_draw_color_picker(out, &matrix, &hue_bar, (fmt ==
NK_RGBA) ? &alpha_bar:0, *col);
24284 config = &ctx->
style;
24287 if (!state)
return 0;
24334 if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
24335 (!is_open && !is_active && !is_clicked))
return 0;
24336 if (!nk_nonblock_begin(ctx, 0, body,
24358 NK_ASSERT(selected);
24365 style = &ctx->
style;
24386 text.background =
nk_rgba(0,0,0,0);
24389 text.background = background->
data.
color;
24402 else if (is_clicked)
24410 button.h = button.w;
24423 nk_widget_text(&win->
buffer, label, selected, len, &text,
24430 return nk_combo_begin(ctx, win, size, is_clicked, header);
24456 style = &ctx->
style;
24486 else if (is_clicked)
24494 button.h = button.w;
24512 return nk_combo_begin(ctx, win, size, is_clicked, header);
24535 style = &ctx->
style;
24557 sym_background =
nk_rgba(0,0,0,0);
24560 sym_background = background->
data.
color;
24565 struct nk_rect bounds = {0,0,0,0};
24572 else if (is_clicked)
24580 button.h = button.w;
24592 nk_draw_symbol(&win->
buffer, symbol, bounds, sym_background, symbol_color,
24593 1.0f, style->
font);
24599 return nk_combo_begin(ctx, win, size, is_clicked, header);
24623 style = &ctx->
style;
24646 text.background =
nk_rgba(0,0,0,0);
24649 text.background = background->
data.
color;
24662 else if (is_clicked)
24670 button.h = button.w;
24684 nk_draw_symbol(&win->
buffer, symbol, image, text.background, symbol_color,
24685 1.0f, style->
font);
24695 return nk_combo_begin(ctx, win, size, is_clicked, header);
24716 style = &ctx->
style;
24739 struct nk_rect bounds = {0,0,0,0};
24746 else if (is_clicked)
24754 button.h = button.w;
24772 return nk_combo_begin(ctx, win, size, is_clicked, header);
24795 style = &ctx->
style;
24815 text.background =
nk_rgba(0,0,0,0);
24818 text.background = background->
data.
color;
24831 else if (is_clicked)
24839 button.h = button.w;
24863 return nk_combo_begin(ctx, win, size, is_clicked, header);
24895 const char *text,
nk_flags alignment)
24901 const char *text,
int len,
nk_flags alignment)
24907 const char *label,
nk_flags alignment)
24921 int selected,
int item_height,
struct nk_vec2 size)
24926 struct nk_vec2 window_padding;
24931 if (!ctx || !items ||!count)
24936 max_height = count * item_height + count * (int)item_spacing.y;
24937 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
24938 size.
y =
NK_MIN(size.
y, (
float)max_height);
24941 for (i = 0; i < count; ++i) {
24951 int separator,
int selected,
int count,
int item_height,
struct nk_vec2 size)
24956 struct nk_vec2 window_padding;
24957 const char *current_item;
24962 NK_ASSERT(items_separated_by_separator);
24963 if (!ctx || !items_separated_by_separator)
24969 max_height = count * item_height + count * (int)item_spacing.y;
24970 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
24971 size.
y =
NK_MIN(size.
y, (
float)max_height);
24974 current_item = items_separated_by_separator;
24975 for (i = 0; i < count; ++i) {
24976 iter = current_item;
24977 while (*iter && *iter != separator) iter++;
24978 length = (int)(iter - current_item);
24979 if (i == selected)
break;
24980 current_item = iter + 1;
24984 current_item = items_separated_by_separator;
24986 for (i = 0; i < count; ++i) {
24987 iter = current_item;
24988 while (*iter && *iter != separator) iter++;
24989 length = (int)(iter - current_item);
24992 current_item = current_item + length + 1;
25000 int selected,
int count,
int item_height,
struct nk_vec2 size)
25002 return nk_combo_separator(ctx, items_separated_by_zeros,
'\0', selected, count, item_height, size);
25006 void *userdata,
int selected,
int count,
int item_height,
struct nk_vec2 size)
25011 struct nk_vec2 window_padding;
25015 NK_ASSERT(item_getter);
25016 if (!ctx || !item_getter)
25022 max_height = count * item_height + count * (int)item_spacing.y;
25023 max_height += (
int)item_spacing.y * 2 + (int)window_padding.y * 2;
25024 size.
y =
NK_MIN(size.
y, (
float)max_height);
25026 item_getter(userdata, selected, &item);
25029 for (i = 0; i < count; ++i) {
25030 item_getter(userdata, i, &item);
25039 int *selected,
int item_height,
struct nk_vec2 size)
25041 *selected =
nk_combo(ctx, items, count, *selected, item_height, size);
25045 int *selected,
int count,
int item_height,
struct nk_vec2 size)
25047 *selected =
nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
25051 int separator,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
25054 *selected, count, item_height, size);
25058 void(*item_getter)(
void* data,
int id,
const char **out_text),
25059 void *userdata,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
25061 *selected =
nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
25094 w = nk_iceilf(width);
25095 h = nk_iceilf(nk_null_rect.h);
25099 bounds.
x = (
float)
x;
25100 bounds.
y = (float)
y;
25101 bounds.
w = (float)
w;
25102 bounds.
h = (float)
h;
25117 if (!ctx || !ctx->
current)
return;
25140 style = &ctx->
style;
25147 text_width += (4 * padding.
x);
25148 text_height = (style->
font->
height + 2 * padding.
y);
25157 #ifdef NK_INCLUDE_STANDARD_VARARGS 25159 nk_tooltipf(
struct nk_context *ctx,
const char *fmt, ...)
25162 va_start(args, fmt);
25163 nk_tooltipfv(ctx, fmt, args);
25167 nk_tooltipfv(
struct nk_context *ctx,
const char *fmt, va_list args)
25170 nk_strfmt(buf,
NK_LEN(buf), fmt, args);
void(* draw_begin)(struct nk_command_buffer *, nk_handle)
NK_API struct nk_color nk_rgb_iv(const int *rgb)
NK_API int nk_menu_item_text(struct nk_context *, const char *, int, nk_flags align)
struct nk_style_item hover
struct nk_style_item hover_active
NK_API int nk_window_has_focus(const struct nk_context *)
NK_API int nk_menu_item_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags alignment)
struct nk_style_button dec_button
NK_API struct nk_rect nk_rectv(const float *xywh)
#define NK_CONFIG_STACK(type, size)
struct nk_style_item cursor_hover
NK_API int nk_input_mouse_clicked(const struct nk_input *, enum nk_buttons, struct nk_rect)
struct nk_style_item active
NK_API int nk_select_text(struct nk_context *, const char *, int, nk_flags align, int value)
NK_API int nk_tree_state_image_push(struct nk_context *, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state)
NK_API struct nk_color nk_rgba_bv(const nk_byte *rgba)
NK_API int nk_contextual_item_image_text(struct nk_context *, struct nk_image, const char *, int len, nk_flags alignment)
NK_API void nk_textedit_select_all(struct nk_text_edit *)
NK_API int nk_button_symbol_label_styled(struct nk_context *ctx, const struct nk_style_button *style, enum nk_symbol_type symbol, const char *title, nk_flags align)
NK_API int nk_contextual_begin(struct nk_context *, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds)
struct nk_color text_hover
struct nk_style_item cursor_normal
NK_API void nk_color_hex_rgb(char *output, struct nk_color)
NK_API struct nk_rect nk_get_null_rect(void)
nk_buffer_allocation_type
NK_API int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags)
NK_API int nk_contextual_item_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags alignment)
NK_API int nk_filter_default(const struct nk_text_edit *, nk_rune unicode)
NK_API void nk_stroke_circle(struct nk_command_buffer *, struct nk_rect, float line_thickness, struct nk_color)
NK_API struct nk_vec2 nk_vec2i(int x, int y)
struct nk_vec2 contextual_padding
NK_API int nk_utf_decode(const char *, nk_rune *, int)
struct nk_style_button menu_button
NK_API struct nk_color nk_rgba_u32(nk_uint)
float(* nk_text_width_f)(nk_handle, float h, const char *, int len)
NK_API int nk_filter_hex(const struct nk_text_edit *, nk_rune unicode)
NK_API int nk_menu_item_image_text(struct nk_context *, struct nk_image, const char *, int len, nk_flags alignment)
NK_API void nk_buffer_init(struct nk_buffer *, const struct nk_allocator *, nk_size size)
NK_API int nk_button_color(struct nk_context *, struct nk_color)
NK_API int nk_select_image_text(struct nk_context *, struct nk_image, const char *, int, nk_flags align, int value)
NK_API struct nk_window * nk_window_find(struct nk_context *ctx, const char *name)
NK_API void nk_str_remove_chars(struct nk_str *, int len)
NK_API int nk_widget_is_hovered(struct nk_context *)
#define NK_FLAGS_STACK_SIZE
NK_API void nk_layout_row_end(struct nk_context *)
NK_API void nk_fill_circle(struct nk_command_buffer *, struct nk_rect, struct nk_color)
#define nk_zero_struct(s)
enum nk_symbol_type sym_left
struct nk_config_stack_button_behavior button_behaviors
struct nk_color selected_text_hover
NK_API int nk_combo_callback(struct nk_context *, void(*item_getter)(void *, int, const char **), void *userdata, int selected, int count, int item_height, struct nk_vec2 size)
NK_API int nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, int down)
NK_API void nk_colorf_hsva_fv(float *hsva, struct nk_colorf in)
NK_API void nk_str_init_fixed(struct nk_str *, void *memory, nk_size size)
NK_API int nk_popup_begin(struct nk_context *, enum nk_popup_type, const char *, nk_flags, struct nk_rect bounds)
NK_API void nk_property_float(struct nk_context *, const char *name, float min, float *val, float max, float step, float inc_per_pixel)
NK_API void nk_layout_row_template_push_variable(struct nk_context *, float min_width)
struct nk_vec2 touch_padding
NK_API int nk_button_text_styled(struct nk_context *, const struct nk_style_button *, const char *title, int len)
unsigned short line_thickness
struct nk_style_button node_maximize_button
NK_API void nk_layout_row_template_push_static(struct nk_context *, float width)
NK_API void nk_color_hsv_iv(int *hsv_out, struct nk_color)
struct nk_vec2 tooltip_padding
NK_API void nk_combobox_callback(struct nk_context *, void(*item_getter)(void *, int, const char **), void *, int *selected, int count, int item_height, struct nk_vec2 size)
NK_API int nk_combo_item_text(struct nk_context *, const char *, int, nk_flags alignment)
NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context *, nk_flags, char *buffer, int max, nk_plugin_filter)
struct nk_window * current
NK_API void nk_text(struct nk_context *, const char *, int, nk_flags)
nk_uint values[NK_VALUE_PAGE_CAPACITY]
NK_API int nk_select_label(struct nk_context *, const char *, nk_flags align, int value)
NK_API int nk_menu_item_label(struct nk_context *, const char *, nk_flags alignment)
NK_API struct nk_rect nk_layout_widget_bounds(struct nk_context *)
struct nk_color selected_text_normal
NK_API int nk_button_symbol_styled(struct nk_context *, const struct nk_style_button *, enum nk_symbol_type)
struct nk_chart_slot slots[NK_CHART_MAX_SLOT]
struct nk_color text_normal_active
char nk_glyph[NK_UTF_SIZE]
NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context *, struct nk_rect)
NK_API struct nk_color nk_hsv(int h, int s, int v)
struct nk_color tooltip_border_color
struct nk_vec2 image_padding
struct nk_vec2 cursor_size
struct nk_color group_border_color
struct nk_style_item scaler
NK_API void nk_edit_focus(struct nk_context *, nk_flags flags)
unsigned short point_count
#define NK_MAX_FLOAT_PRECISION
#define NK_MAX_NUMBER_BUFFER
NK_API struct nk_color nk_hsv_fv(const float *hsv)
NK_API struct nk_style_item nk_style_item_image(struct nk_image img)
NK_API int nk_widget_is_mouse_clicked(struct nk_context *, enum nk_buttons)
struct nk_color bar_hover
struct nk_style_progress progress
NK_API void nk_window_collapse(struct nk_context *, const char *name, enum nk_collapse_states state)
NK_API void nk_button_set_behavior(struct nk_context *, enum nk_button_behavior)
NK_API void nk_group_end(struct nk_context *)
NK_API int nk_input_is_key_pressed(const struct nk_input *, enum nk_keys)
unsigned short point_count
struct nk_style_item normal
unsigned short line_thickness
struct nk_property_state property
NK_API void nk_layout_space_end(struct nk_context *)
struct nk_style_item active
struct nk_style_item cursor_hover
struct nk_color border_color
struct nk_color text_pressed
NK_API void nk_layout_row_template_push_dynamic(struct nk_context *)
struct nk_page_element * freelist
struct nk_style_selectable selectable
NK_API int nk_str_insert_str_runes(struct nk_str *, int pos, const nk_rune *)
void(* draw_begin)(struct nk_command_buffer *, nk_handle)
enum nk_symbol_type sym_minimize
struct nk_style_button inc_button
struct nk_style_window window
NK_API void nk_stroke_triangle(struct nk_command_buffer *, float, float, float, float, float, float, float line_thichness, struct nk_color)
unsigned short line_thickness
struct nk_color border_color
struct nk_color text_normal
struct nk_style_button contextual_button
NK_API void nk_label_wrap(struct nk_context *, const char *)
NK_API struct nk_color nk_hsv_bv(const nk_byte *hsv)
NK_API int nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score)
NK_API void nk_window_set_focus(struct nk_context *, const char *name)
NK_API void nk_str_delete_runes(struct nk_str *, int pos, int len)
NK_API struct nk_color nk_hsva_bv(const nk_byte *hsva)
NK_API int nk_utf_encode(nk_rune, char *, int)
NK_API void nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color)
NK_API int nk_str_append_text_char(struct nk_str *, const char *, int)
struct nk_color border_color
NK_API struct nk_colorf nk_hsva_colorfv(float *c)
NK_API void nk_fill_rect_multi_color(struct nk_command_buffer *, struct nk_rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom)
NK_API void nk_list_view_end(struct nk_list_view *)
NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context *, struct nk_vec2)
NK_API char * nk_str_at_rune(struct nk_str *, int pos, nk_rune *unicode, int *len)
struct nk_mouse_button buttons[NK_BUTTON_MAX]
unsigned char has_preferred_x
NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context *, struct nk_rect)
struct nk_window * parent
union nk_style_item_data data
NK_API nk_uint nk_color_u32(struct nk_color)
NK_API struct nk_vec2 nk_widget_position(struct nk_context *)
struct nk_color background
NK_API int nk_button_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags alignment)
NK_API int nk_filter_ascii(const struct nk_text_edit *, nk_rune unicode)
NK_API int nk_contextual_item_text(struct nk_context *, const char *, int, nk_flags align)
struct nk_page_element * next
NK_API int nk_str_insert_text_char(struct nk_str *, int pos, const char *, int)
struct nk_window * active
struct nk_color highlight
struct nk_style_text text
struct nk_color text_pressed_active
struct nk_color label_normal
struct nk_color combo_border_color
NK_API void nk_textedit_text(struct nk_text_edit *, const char *, int total_len)
NK_API void nk_str_delete_chars(struct nk_str *, int pos, int len)
struct nk_allocator alloc
NK_API int nk_str_append_text_runes(struct nk_str *, const nk_rune *, int)
nk_command_custom_callback callback
NK_API void nk_color_f(float *r, float *g, float *b, float *a, struct nk_color)
NK_API void nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color)
struct nk_vec2 scrollbar_size
NK_API int nk_strtoi(const char *str, const char **endptr)
enum nk_symbol_type sym_normal
struct nk_style_item cursor_hover
struct nk_key keys[NK_KEY_MAX]
NK_API struct nk_style_item nk_style_item_hide(void)
NK_API int nk_combo_item_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags alignment)
unsigned short line_thickness
NK_API void nk_label(struct nk_context *, const char *, nk_flags align)
NK_API int nk_style_set_cursor(struct nk_context *, enum nk_style_cursor)
NK_API const struct nk_command * nk__next(struct nk_context *, const struct nk_command *)
NK_API int nk_stricmp(const char *s1, const char *s2)
NK_API int nk_str_insert_at_rune(struct nk_str *, int pos, const char *, int)
NK_API void nk_plot(struct nk_context *, enum nk_chart_type, const float *values, int count, int offset)
unsigned curve_segment_count
NK_API void nk_contextual_end(struct nk_context *)
NK_API int nk_combo_item_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags alignment)
struct nk_command_buffer overlay
NK_API int nk_progress(struct nk_context *, nk_size *cur, nk_size max, int modifyable)
struct nk_style_item normal
struct nk_style_item active
struct nk_style_edit edit
NK_API int nk_window_is_any_hovered(struct nk_context *)
NK_API struct nk_vec2 nk_vec2iv(const int *xy)
unsigned char cursor_at_end_of_line
NK_API int nk_combo_begin_text(struct nk_context *, const char *selected, int, struct nk_vec2 size)
#define NK_BUTTON_BEHAVIOR_STACK_SIZE
struct nk_style_button dec_button
NK_API void nk_input_glyph(struct nk_context *, const nk_glyph)
struct nk_style_item pressed_active
void(* nk_plugin_paste)(nk_handle, struct nk_text_edit *)
NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context *, struct nk_vec2)
NK_API int nk_style_pop_float(struct nk_context *)
void(* draw_end)(struct nk_command_buffer *, nk_handle)
NK_API struct nk_rect nk_layout_space_bounds(struct nk_context *)
float min_row_height_padding
NK_API int nk_button_image_text_styled(struct nk_context *, const struct nk_style_button *, struct nk_image img, const char *, int, nk_flags alignment)
NK_API int nk_init_custom(struct nk_context *, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *)
struct nk_vec2i points[1]
struct nk_color border_color
NK_API int nk_select_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags align, int value)
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect *, struct nk_context *, struct nk_vec2)
NK_API double nk_strtod(const char *str, const char **endptr)
NK_API void nk_window_close(struct nk_context *ctx, const char *name)
int(* nk_plugin_filter)(const struct nk_text_edit *, nk_rune unicode)
NK_API void nk_style_default(struct nk_context *)
NK_API void nk_input_scroll(struct nk_context *, struct nk_vec2 val)
NK_API int nk_input_has_mouse_click_down_in_rect(const struct nk_input *, enum nk_buttons, struct nk_rect, int down)
#define NK_FLOAT_STACK_SIZE
NK_API void nk_free(struct nk_context *)
struct nk_color text_normal
unsigned short point_count
NK_API char * nk_str_at_char(struct nk_str *, int pos)
NK_API int nk_button_label_styled(struct nk_context *, const struct nk_style_button *, const char *title)
NK_API struct nk_color nk_rgb(int r, int g, int b)
NK_API int nk_tree_push_hashed(struct nk_context *, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len, int seed)
enum nk_symbol_type sym_active
NK_API void nk_layout_space_push(struct nk_context *, struct nk_rect bounds)
NK_API void nk_combobox_separator(struct nk_context *, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size)
unsigned int has_scrolling
NK_API void nk_tree_state_pop(struct nk_context *)
NK_API int nk_combo_begin_label(struct nk_context *, const char *selected, struct nk_vec2 size)
NK_API int nk_stricmpn(const char *s1, const char *s2, int n)
NK_API int nk_style_push_flags(struct nk_context *, nk_flags *, nk_flags)
struct nk_style_item active
NK_API void nk_window_collapse_if(struct nk_context *, const char *name, enum nk_collapse_states, int cond)
struct nk_vec2 button_padding
NK_API void nk_layout_reset_min_row_height(struct nk_context *)
NK_API struct nk_colorf nk_color_cf(struct nk_color)
float templates[NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS]
NK_API void nk_buffer_push(struct nk_buffer *, enum nk_buffer_allocation_type type, const void *memory, nk_size size, nk_size align)
NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx)
NK_API void nk_color_fv(float *rgba_out, struct nk_color)
NK_API int nk_input_is_mouse_prev_hovering_rect(const struct nk_input *, struct nk_rect)
unsigned arc_segment_count
void(* draw_end)(struct nk_command_buffer *, nk_handle)
NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols)
const struct nk_cursor * cursor_active
unsigned circle_segment_count
enum nk_symbol_type dec_symbol
struct nk_style_button button
struct nk_style_scrollbar scrollh
NK_API int nk_input_is_mouse_click_in_rect(const struct nk_input *, enum nk_buttons, struct nk_rect)
NK_API void nk_group_scrolled_end(struct nk_context *)
NK_API int nk_contextual_item_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags alignment)
unsigned char single_line
struct nk_color foreground
NK_API void nk_layout_set_min_row_height(struct nk_context *, float height)
struct nk_style_item normal
NK_API struct nk_vec2 nk_vec2(float x, float y)
NK_API void nk_menubar_end(struct nk_context *)
struct nk_vec2 scrollbar_size
NK_API void nk_buffer_mark(struct nk_buffer *, enum nk_buffer_allocation_type type)
#define NK_WINDOW_MAX_NAME
struct nk_config_stack_user_font fonts
NK_API int nk_combo_begin_symbol(struct nk_context *, enum nk_symbol_type, struct nk_vec2 size)
NK_API void nk_image(struct nk_context *, struct nk_image)
#define NK_VECTOR_STACK_SIZE
struct nk_draw_null_texture null
NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols)
NK_API int nk_strlen(const char *str)
struct nk_style_item normal
NK_API void nk_tree_element_pop(struct nk_context *)
NK_API float nk_strtof(const char *str, const char **endptr)
struct nk_color bar_active
struct nk_color cursor_text_normal
NK_API struct nk_color nk_rgb_fv(const float *rgb)
NK_API int nk_color_pick(struct nk_context *, struct nk_colorf *, enum nk_color_format)
NK_API int nk_window_is_collapsed(struct nk_context *ctx, const char *name)
NK_API void nk_draw_text(struct nk_command_buffer *, struct nk_rect, const char *text, int len, const struct nk_user_font *, struct nk_color, struct nk_color)
enum nk_allocation_type type
NK_API struct nk_color nk_hsva_iv(const int *hsva)
NK_API void nk_combobox(struct nk_context *, const char **items, int count, int *selected, int item_height, struct nk_vec2 size)
struct nk_scroll scrollbar
NK_API void nk_buffer_reset(struct nk_buffer *, enum nk_buffer_allocation_type type)
NK_API int nk_str_insert_text_runes(struct nk_str *, int pos, const nk_rune *, int)
enum nk_symbol_type sym_maximize
void(* nk_command_custom_callback)(void *canvas, short x, short y, unsigned short w, unsigned short h, nk_handle callback_data)
NK_API void nk_textedit_delete_selection(struct nk_text_edit *)
NK_API void nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color)
NK_API struct nk_color nk_rgba(int r, int g, int b, int a)
NK_API void * nk_buffer_memory(struct nk_buffer *)
NK_API void nk_textedit_init_fixed(struct nk_text_edit *, void *memory, nk_size size)
NK_API int nk_init_fixed(struct nk_context *, void *memory, nk_size size, const struct nk_user_font *)
struct nk_style_slider slider
struct nk_color label_active
NK_API void nk_stroke_curve(struct nk_command_buffer *, float, float, float, float, float, float, float, float, float line_thickness, struct nk_color)
NK_API int nk_button_image(struct nk_context *, struct nk_image img)
NK_API struct nk_image nk_subimage_handle(nk_handle, unsigned short w, unsigned short h, struct nk_rect sub_region)
NK_API int nk_combo(struct nk_context *, const char **items, int count, int selected, int item_height, struct nk_vec2 size)
NK_API struct nk_color nk_rgba_f(float r, float g, float b, float a)
NK_API void nk_str_clear(struct nk_str *)
#define NK_TEXTEDIT_UNDOCHARCOUNT
NK_API const void * nk_buffer_memory_const(const struct nk_buffer *)
#define nk_ptr_add_const(t, p, i)
NK_API void nk_buffer_init_fixed(struct nk_buffer *, void *memory, nk_size size)
NK_API void nk_layout_row_template_begin(struct nk_context *, float row_height)
NK_API void nk_popup_close(struct nk_context *)
NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color)
struct nk_page_element * freelist
struct nk_vec2 combo_padding
NK_API int nk_str_append_text_utf8(struct nk_str *, const char *, int)
struct nk_color text_hover
NK_API void nk_text_colored(struct nk_context *, const char *, int, nk_flags, struct nk_color)
struct nk_config_stack_flags flags
NK_API int nk_checkbox_flags_text(struct nk_context *, const char *, int, unsigned int *flags, unsigned int value)
NK_API int nk_button_image_styled(struct nk_context *, const struct nk_style_button *, struct nk_image img)
unsigned short line_thickness
NK_API struct nk_rect nk_rect(float x, float y, float w, float h)
NK_API void nk_style_show_cursor(struct nk_context *)
struct nk_color text_background
struct nk_style_scrollbar scrollv
NK_API void nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type, struct nk_color, struct nk_color active, int count, float min_value, float max_value)
NK_API struct nk_colorf nk_color_picker(struct nk_context *, struct nk_colorf, enum nk_color_format)
NK_API int nk_style_push_font(struct nk_context *, const struct nk_user_font *)
enum nk_anti_aliasing line_AA
NK_API int nk_group_scrolled_offset_begin(struct nk_context *, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
NK_API int nk_tree_element_image_push_hashed(struct nk_context *, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, int *selected, const char *hash, int len, int seed)
NK_API const char * nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len)
NK_API int nk_chart_begin_colored(struct nk_context *, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max)
NK_API void nk_style_hide_cursor(struct nk_context *)
NK_API int nk_menu_begin_image_text(struct nk_context *, const char *, int, nk_flags align, struct nk_image, struct nk_vec2 size)
struct nk_color border_color
NK_API void nk_str_remove_runes(struct nk_str *str, int len)
#define NK_ALIGN_PTR(x, mask)
NK_API int nk_widget_has_mouse_click_down(struct nk_context *, enum nk_buttons, int down)
#define NK_CLAMP(i, v, x)
struct nk_style_combo combo
struct nk_style_property property
NK_API void nk_input_begin(struct nk_context *)
struct nk_color contextual_border_color
NK_API int nk_option_text(struct nk_context *, const char *, int, int active)
struct nk_menu_state menu
NK_API void nk_stroke_rect(struct nk_command_buffer *, struct nk_rect, float rounding, float line_thickness, struct nk_color)
NK_API int nk_menu_begin_symbol_text(struct nk_context *, const char *, int, nk_flags align, enum nk_symbol_type, struct nk_vec2 size)
NK_API void nk_push_scissor(struct nk_command_buffer *, struct nk_rect)
NK_API const struct nk_command * nk__begin(struct nk_context *)
void(* draw_begin)(struct nk_command_buffer *, nk_handle)
NK_API nk_flags nk_chart_push_slot(struct nk_context *, float, int)
#define NK_INBOX(px, py, x, y, w, h)
#define nk_vec2_sub(a, b)
NK_API int nk_str_append_str_char(struct nk_str *, const char *)
struct nk_color selected_color
unsigned char initialized
NK_API int nk_input_is_key_down(const struct nk_input *, enum nk_keys)
NK_API int nk_window_is_hovered(struct nk_context *)
NK_API double nk_propertyd(struct nk_context *, const char *name, double min, double val, double max, double step, float inc_per_pixel)
struct nk_cursor * cursor_last
NK_API int nk_filter_decimal(const struct nk_text_edit *, nk_rune unicode)
NK_API int nk_filter_binary(const struct nk_text_edit *, nk_rune unicode)
NK_API int nk_init(struct nk_context *, struct nk_allocator *, const struct nk_user_font *)
NK_API int nk_radio_label(struct nk_context *, const char *, int *active)
NK_API void nk_contextual_close(struct nk_context *)
NK_API int nk_input_has_mouse_click_in_rect(const struct nk_input *, enum nk_buttons, struct nk_rect)
NK_API void nk_textedit_init(struct nk_text_edit *, struct nk_allocator *, nk_size size)
const struct nk_cursor * cursors[NK_CURSOR_COUNT]
const struct nk_draw_vertex_layout_element * vertex_layout
struct nk_style_chart chart
struct nk_vec2 popup_padding
NK_API void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols)
NK_API void nk_fill_arc(struct nk_command_buffer *, float cx, float cy, float radius, float a_min, float a_max, struct nk_color)
NK_API const char * nk_str_get_const(const struct nk_str *)
NK_API int nk_textedit_cut(struct nk_text_edit *)
NK_API void nk_property_double(struct nk_context *, const char *name, double min, double *val, double max, double step, float inc_per_pixel)
struct nk_color cursor_text_hover
NK_API int nk_button_image_label_styled(struct nk_context *, const struct nk_style_button *, struct nk_image img, const char *, nk_flags text_alignment)
NK_API int nk_combo_separator(struct nk_context *, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size)
NK_API void nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color)
NK_API void nk_stroke_polyline(struct nk_command_buffer *, float *points, int point_count, float line_thickness, struct nk_color col)
NK_API void nk_text_wrap_colored(struct nk_context *, const char *, int, struct nk_color)
NK_API enum nk_widget_layout_states nk_widget(struct nk_rect *, const struct nk_context *)
NK_API struct nk_vec2 nk_rect_pos(struct nk_rect)
struct nk_text_undo_state undo
NK_API int nk_input_is_mouse_released(const struct nk_input *, enum nk_buttons)
NK_API void nk_property_int(struct nk_context *, const char *name, int min, int *val, int max, int step, float inc_per_pixel)
struct nk_style_button button
#define NK_SCROLLBAR_HIDING_TIMEOUT
enum nk_symbol_type sym_right
NK_API struct nk_colorf nk_hsva_colorf(float h, float s, float v, float a)
NK_API void nk_color_hex_rgba(char *output, struct nk_color)
struct nk_vec2 group_padding
NK_API void nk_style_load_cursor(struct nk_context *, enum nk_style_cursor, const struct nk_cursor *)
NK_API int nk_select_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags align, int value)
NK_API int nk_input_is_mouse_pressed(const struct nk_input *, enum nk_buttons)
struct nk_style_item cursor_normal
#define NK_VALUE_PAGE_CAPACITY
NK_API void nk_push_custom(struct nk_command_buffer *, struct nk_rect, nk_command_custom_callback, nk_handle usr)
NK_API int nk_str_len_char(struct nk_str *)
NK_API int nk_input_any_mouse_click_in_rect(const struct nk_input *, struct nk_rect)
NK_API const char * nk_style_get_color_by_name(enum nk_style_colors)
NK_API void nk_stroke_arc(struct nk_command_buffer *, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, struct nk_color)
NK_API void nk_tooltip_end(struct nk_context *)
struct nk_color border_color
struct nk_style_item cursor_normal
NK_API void nk_spacing(struct nk_context *, int cols)
NK_API struct nk_color nk_rgba_hex(const char *rgb)
struct nk_vec2i points[1]
struct nk_style_item active
NK_API int nk_button_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags text_alignment)
#define NK_STATIC_ASSERT(exp)
NK_API struct nk_image nk_subimage_ptr(void *, unsigned short w, unsigned short h, struct nk_rect sub_region)
NK_API void nk_text_wrap(struct nk_context *, const char *, int)
NK_API struct nk_image nk_image_handle(nk_handle)
NK_API struct nk_image nk_image_ptr(void *)
NK_API float nk_window_get_width(const struct nk_context *)
NK_API int nk_image_is_subimage(const struct nk_image *img)
struct nk_style_item hover
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
struct nk_color text_hover_active
NK_API int nk_selectable_label(struct nk_context *, const char *, nk_flags align, int *value)
struct nk_style_button tab_minimize_button
NK_API struct nk_color nk_hsva(int h, int s, int v, int a)
#define NK_STYLE_ITEM_STACK_SIZE
NK_API int nk_str_insert_text_utf8(struct nk_str *, int pos, const char *, int)
NK_API void nk_tooltip(struct nk_context *, const char *)
struct nk_color text_active
#define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS
NK_API void nk_combo_close(struct nk_context *)
struct nk_color text_hover
NK_API int nk_radio_text(struct nk_context *, const char *, int, int *active)
NK_API void nk_buffer_clear(struct nk_buffer *)
enum nk_symbol_type sym_hover
void *(* nk_plugin_alloc)(nk_handle, void *old, nk_size)
NK_API struct nk_vec2 nk_window_get_size(const struct nk_context *)
struct nk_color label_hover
NK_API const char * nk_str_at_char_const(const struct nk_str *, int pos)
struct nk_configuration_stacks stacks
NK_API nk_handle nk_handle_id(int)
NK_API int nk_combo_item_image_label(struct nk_context *, struct nk_image, const char *, nk_flags alignment)
NK_API struct nk_color nk_rgb_f(float r, float g, float b)
enum nk_allocation_type type
struct nk_color symbol_hover
NK_API int nk_contextual_item_label(struct nk_context *, const char *, nk_flags align)
#define NK_CONFIGURATION_STACK_TYPE(prefix, name, type)
NK_API int nk_list_view_begin(struct nk_context *, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count)
NK_API void nk_stroke_polygon(struct nk_command_buffer *, float *, int point_count, float line_thickness, struct nk_color)
NK_API void nk_popup_end(struct nk_context *)
NK_API void nk_input_motion(struct nk_context *, int x, int y)
NK_API int nk_textedit_paste(struct nk_text_edit *, char const *, int len)
NK_API int nk_utf_len(const char *, int byte_len)
NK_API void nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading)
NK_API struct nk_color nk_hsva_fv(const float *hsva)
enum nk_symbol_type inc_symbol
NK_API void nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color)
#define NK_TEXTEDIT_UNDOSTATECOUNT
NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type, int count, float min_value, float max_value)
struct nk_style_scrollbar scrollbar
struct nk_color bar_normal
nk_flags last_widget_state
#define nk_foreach(c, ctx)
struct nk_style_item normal_active
NK_API float nk_window_get_height(const struct nk_context *)
NK_API float nk_widget_height(struct nk_context *)
NK_API int nk_menu_item_image_label(struct nk_context *, struct nk_image, const char *, nk_flags alignment)
NK_API int nk_slide_int(struct nk_context *, int min, int val, int max, int step)
NK_API int nk_filter_oct(const struct nk_text_edit *, nk_rune unicode)
NK_API struct nk_rect nk_recta(struct nk_vec2 pos, struct nk_vec2 size)
NK_API int nk_slider_float(struct nk_context *, float min, float *val, float max, float step)
NK_API int nk_window_is_hidden(struct nk_context *, const char *)
NK_API void nk_fill_triangle(struct nk_command_buffer *, float x0, float y0, float x1, float y1, float x2, float y2, struct nk_color)
struct nk_command_buffer buffer
NK_API int nk_slider_int(struct nk_context *, int min, int *val, int max, int step)
NK_API int nk_contextual_item_image_label(struct nk_context *, struct nk_image, const char *, nk_flags alignment)
NK_API void nk_input_button(struct nk_context *, enum nk_buttons, int x, int y, int down)
NK_API int nk_item_is_any_active(struct nk_context *)
NK_API void nk_label_colored_wrap(struct nk_context *, const char *, struct nk_color)
struct nk_style_toggle checkbox
NK_API void nk_input_key(struct nk_context *, enum nk_keys, int down)
void(* nk_plugin_free)(nk_handle, void *old)
NK_API struct nk_style_item nk_style_item_color(struct nk_color)
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
NK_API int nk_button_push_behavior(struct nk_context *, enum nk_button_behavior)
#define nk_ptr_add(t, p, i)
NK_API float nk_slide_float(struct nk_context *, float min, float val, float max, float step)
NK_API void nk_color_hsva_fv(float *hsva_out, struct nk_color)
NK_API void nk_fill_polygon(struct nk_command_buffer *, float *, int point_count, struct nk_color)
NK_API int nk_selectable_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags align, int *value)
NK_API float nk_widget_width(struct nk_context *)
struct nk_color border_color
#define nk_vec2_add(a, b)
NK_API int nk_input_is_mouse_hovering_rect(const struct nk_input *, struct nk_rect)
NK_API int nk_chart_begin(struct nk_context *, enum nk_chart_type, int num, float min, float max)
NK_API int nk_style_pop_vec2(struct nk_context *)
struct nk_config_stack_style_item style_items
NK_API nk_size nk_buffer_total(struct nk_buffer *)
NK_API nk_handle nk_handle_ptr(void *)
struct nk_style_item cursor_active
NK_API void nk_window_show(struct nk_context *, const char *name, enum nk_show_states)
NK_API void nk_tree_pop(struct nk_context *)
const struct nk_user_font * font
NK_API void nk_textedit_undo(struct nk_text_edit *)
NK_API unsigned nk_check_flags_text(struct nk_context *, const char *, int, unsigned int flags, unsigned int value)
struct nk_popup_state popup
NK_API float nk_layout_ratio_from_pixel(struct nk_context *, float pixel_width)
NK_API nk_flags nk_edit_buffer(struct nk_context *, nk_flags, struct nk_text_edit *, nk_plugin_filter)
NK_API int nk_style_pop_style_item(struct nk_context *)
NK_API int nk_checkbox_flags_label(struct nk_context *, const char *, unsigned int *flags, unsigned int value)
struct nk_color symbol_active
nk_rune undo_char[NK_TEXTEDIT_UNDOCHARCOUNT]
float scrollbar_hiding_timer
NK_API struct nk_color nk_rgb_cf(struct nk_colorf c)
NK_API int nk_str_append_str_utf8(struct nk_str *, const char *)
NK_API int nk_window_is_active(struct nk_context *, const char *)
void(* draw_begin)(struct nk_command_buffer *, nk_handle)
unsigned short line_thickness
struct nk_style_window_header header
NK_API int nk_style_push_color(struct nk_context *, struct nk_color *, struct nk_color)
NK_API void nk_style_load_all_cursors(struct nk_context *, struct nk_cursor *)
NK_API void nk_window_set_position(struct nk_context *, const char *name, struct nk_vec2 pos)
struct nk_vec2 touch_padding
struct nk_style_item fixed_background
NK_API int nk_input_has_mouse_click(const struct nk_input *, enum nk_buttons)
NK_API int nk_combo_begin_color(struct nk_context *, struct nk_color color, struct nk_vec2 size)
NK_API void nk_str_free(struct nk_str *)
NK_API int nk_option_label(struct nk_context *, const char *, int active)
NK_API int nk_combo_begin_image_label(struct nk_context *, const char *selected, struct nk_image, struct nk_vec2 size)
struct nk_style_item background
NK_API void nk_image_color(struct nk_context *, struct nk_image, struct nk_color)
NK_API void nk_textedit_free(struct nk_text_edit *)
struct nk_scroll scrollbar
NK_API void nk_color_hsva_iv(int *hsva_out, struct nk_color)
void(* nk_plugin_copy)(nk_handle, const char *, int len)
NK_API struct nk_command_buffer * nk_window_get_canvas(struct nk_context *)
NK_API int nk_checkbox_text(struct nk_context *, const char *, int, int *active)
NK_API int nk_str_len(struct nk_str *)
NK_API nk_flags nk_edit_string(struct nk_context *, nk_flags, char *buffer, int *len, int max, nk_plugin_filter)
NK_API void nk_edit_unfocus(struct nk_context *)
struct nk_style_item hover
void(* nk_query_font_glyph_f)(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint)
NK_API int nk_combo_item_image_text(struct nk_context *, struct nk_image, const char *, int, nk_flags alignment)
NK_API int nk_combo_begin_symbol_text(struct nk_context *, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size)
NK_API int nk_menu_begin_symbol_label(struct nk_context *, const char *, nk_flags align, enum nk_symbol_type, struct nk_vec2 size)
NK_API void nk_buffer_free(struct nk_buffer *)
NK_API struct nk_color nk_hsv_f(float h, float s, float v)
struct nk_style_item cursor_active
struct nk_style_item normal
NK_API int nk_button_symbol(struct nk_context *, enum nk_symbol_type)
NK_API int nk_checkbox_label(struct nk_context *, const char *, int *active)
struct nk_vec2 scroll_delta
NK_API int nk_window_is_closed(struct nk_context *, const char *)
NK_API int nk_selectable_symbol_text(struct nk_context *, enum nk_symbol_type, const char *, int, nk_flags align, int *value)
NK_API int nk_group_begin(struct nk_context *, const char *title, nk_flags)
NK_API void nk_buffer_info(struct nk_memory_status *, struct nk_buffer *)
NK_API const char * nk_str_at_const(const struct nk_str *, int pos, nk_rune *unicode, int *len)
struct nk_color symbol_normal
#define NK_COLOR_STACK_SIZE
void(* draw_end)(struct nk_command_buffer *, nk_handle)
NK_API int nk_tree_element_push_hashed(struct nk_context *, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, int *selected, const char *hash, int len, int seed)
struct nk_style_item normal
enum nk_panel_row_layout_type type
NK_API void nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color)
#define NK_BETWEEN(x, a, b)
NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx)
NK_API void nk_clear(struct nk_context *)
struct nk_color cursor_border_color
struct nk_color border_color
NK_API void nk_menu_end(struct nk_context *)
#define NK_CONTAINER_OF(ptr, type, member)
NK_API void nk_colorf_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_colorf in)
struct nk_style_item hover
NK_API int nk_selectable_image_text(struct nk_context *, struct nk_image, const char *, int, nk_flags align, int *value)
NK_API nk_flags nk_chart_push(struct nk_context *, float)
NK_API unsigned nk_check_flags_label(struct nk_context *, const char *, unsigned int flags, unsigned int value)
NK_API int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags)
NK_API float nk_propertyf(struct nk_context *, const char *name, float min, float val, float max, float step, float inc_per_pixel)
NK_API int nk_input_is_key_released(const struct nk_input *, enum nk_keys)
struct nk_color cursor_hover
struct nk_style_item hover
void(* draw_begin)(struct nk_command_buffer *, nk_handle)
enum nk_command_type type
struct nk_color text_active
NK_API struct nk_rect nk_widget_bounds(struct nk_context *)
struct nk_config_stack_vec2 vectors
NK_API void nk_window_show_if(struct nk_context *, const char *name, enum nk_show_states, int cond)
NK_API int nk_tree_image_push_hashed(struct nk_context *, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len, int seed)
struct nk_color cursor_normal
nk_hash keys[NK_VALUE_PAGE_CAPACITY]
NK_API struct nk_color nk_hsv_iv(const int *hsv)
NK_API int nk_menu_begin_image(struct nk_context *, const char *, struct nk_image, struct nk_vec2 size)
struct nk_color popup_border_color
NK_API int nk_menu_begin_image_label(struct nk_context *, const char *, nk_flags align, struct nk_image, struct nk_vec2 size)
NK_API int nk_str_insert_at_char(struct nk_str *, int pos, const char *, int)
NK_API int nk_selectable_text(struct nk_context *, const char *, int, nk_flags align, int *value)
NK_API void nk_window_set_bounds(struct nk_context *, const char *name, struct nk_rect bounds)
NK_API int nk_input_is_mouse_down(const struct nk_input *, enum nk_buttons)
NK_API nk_size nk_prog(struct nk_context *, nk_size cur, nk_size max, int modifyable)
NK_API int nk_filter_float(const struct nk_text_edit *, nk_rune unicode)
NK_API void nk_input_end(struct nk_context *)
NK_API int nk_button_pop_behavior(struct nk_context *)
struct nk_color selected_normal
NK_API void nk_layout_row(struct nk_context *, enum nk_layout_format, float height, int cols, const float *ratio)
NK_API void nk_layout_row_template_end(struct nk_context *)
NK_API struct nk_color nk_hsva_f(float h, float s, float v, float a)
struct nk_style_edit edit
NK_API int nk_combo_string(struct nk_context *, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size)
struct nk_style_toggle option
NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score)
struct nk_buffer_marker marker[NK_BUFFER_MAX]
NK_API int nk_combo_begin_image_text(struct nk_context *, const char *selected, int, struct nk_image, struct nk_vec2 size)
struct nk_vec2 size offset
struct nk_style_item normal
NK_API int nk_selectable_image_label(struct nk_context *, struct nk_image, const char *, nk_flags align, int *value)
struct nk_style_button node_minimize_button
unsigned short line_thickness
NK_API int nk_check_text(struct nk_context *, const char *, int, int active)
struct nk_text_edit text_edit
NK_API int nk_style_push_style_item(struct nk_context *, struct nk_style_item *, struct nk_style_item)
NK_API void nk_textedit_delete(struct nk_text_edit *, int where, int len)
NK_API nk_hash nk_murmur_hash(const void *key, int len, nk_hash seed)
struct nk_style_item active
char name_string[NK_WINDOW_MAX_NAME]
struct nk_page_element * prev
enum nk_anti_aliasing shape_AA
NK_API int nk_group_scrolled_begin(struct nk_context *, struct nk_scroll *off, const char *title, nk_flags)
NK_API void nk_style_set_font(struct nk_context *, const struct nk_user_font *)
NK_API void nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color)
struct nk_vec2 content_padding
unsigned short line_thickness
enum nk_style_item_type type
NK_API void nk_label_colored(struct nk_context *, const char *, nk_flags align, struct nk_color)
struct nk_color text_normal
struct nk_color label_hover
NK_API int nk_check_label(struct nk_context *, const char *, int active)
struct nk_color bar_filled
NK_API struct nk_color nk_rgba_cf(struct nk_colorf c)
NK_API void nk_end(struct nk_context *ctx)
NK_API int nk_menu_begin_symbol(struct nk_context *, const char *, enum nk_symbol_type, struct nk_vec2 size)
NK_API int nk_strfilter(const char *text, const char *regexp)
NK_API void nk_combobox_string(struct nk_context *, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size)
char buffer[NK_MAX_NUMBER_BUFFER]
NK_API char * nk_str_get(struct nk_str *)
#define NK_CHART_MAX_SLOT
struct nk_text_undo_record undo_rec[NK_TEXTEDIT_UNDOSTATECOUNT]
void(* draw_end)(struct nk_command_buffer *, nk_handle)
NK_API int nk_str_append_str_runes(struct nk_str *, const nk_rune *)
NK_API struct nk_color nk_rgba_fv(const float *rgba)
struct nk_config_stack_float floats
struct nk_style_button tab_maximize_button
NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context *)
NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context *)
NK_API struct nk_rect nk_window_get_content_region(struct nk_context *)
NK_API int nk_select_image_label(struct nk_context *, struct nk_image, const char *, nk_flags align, int value)
NK_API void nk_layout_space_begin(struct nk_context *, enum nk_layout_format, float height, int widget_count)
struct nk_config_stack_color colors
NK_API int nk_group_begin_titled(struct nk_context *, const char *name, const char *title, nk_flags)
struct nk_edit_state edit
struct nk_color label_active
NK_API void nk_style_from_table(struct nk_context *, const struct nk_color *)
NK_API int nk_button_label(struct nk_context *, const char *title)
const struct nk_user_font * font
enum nk_button_behavior button_behavior
NK_API int nk_button_text(struct nk_context *, const char *title, int len)
NK_API void nk_menubar_begin(struct nk_context *)
NK_API int nk_style_push_float(struct nk_context *, float *, float)
#define NK_PTR_TO_UINT(x)
#define NK_FONT_STACK_SIZE
NK_API int nk_combo_item_label(struct nk_context *, const char *, nk_flags alignment)
NK_API int nk_button_image_label(struct nk_context *, struct nk_image img, const char *, nk_flags text_alignment)
NK_API int nk_button_image_text(struct nk_context *, struct nk_image img, const char *, int, nk_flags alignment)
NK_API void nk_color_hsv_fv(float *hsv_out, struct nk_color)
NK_API int nk_str_insert_str_char(struct nk_str *, int pos, const char *)
struct nk_vec2i points[1]
NK_API int nk_menu_begin_label(struct nk_context *, const char *, nk_flags align, struct nk_vec2 size)
NK_API void nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color)
NK_API int nk_style_pop_flags(struct nk_context *)
NK_API int nk_button_symbol_text_styled(struct nk_context *, const struct nk_style_button *, enum nk_symbol_type, const char *, int, nk_flags alignment)
NK_API struct nk_color nk_rgb_hex(const char *rgb)
struct nk_style_item hover
NK_API struct nk_color nk_rgb_bv(const nk_byte *rgb)
NK_API int nk_str_insert_str_utf8(struct nk_str *, int pos, const char *)
NK_API struct nk_image nk_subimage_id(int, unsigned short w, unsigned short h, struct nk_rect sub_region)
struct nk_color text_background
NK_API void nk_plot_function(struct nk_context *, enum nk_chart_type, void *userdata, float(*value_getter)(void *user, int index), int count, int offset)
NK_API nk_rune nk_str_rune_at(const struct nk_str *, int pos)
NK_API int nk_style_pop_font(struct nk_context *)
struct nk_style_item hover
NK_API int nk_tree_state_push(struct nk_context *, enum nk_tree_type, const char *title, enum nk_collapse_states *state)
NK_API void nk_window_set_size(struct nk_context *, const char *name, struct nk_vec2)
NK_API void nk_input_unicode(struct nk_context *, nk_rune)
NK_API void nk_textedit_redo(struct nk_text_edit *)
NK_API void nk_menu_close(struct nk_context *)
NK_API struct nk_vec2 nk_rect_size(struct nk_rect)
struct nk_style_item background
NK_API void nk_str_init(struct nk_str *, const struct nk_allocator *, nk_size size)
NK_API struct nk_image nk_image_id(int)
NK_API int nk_combo_begin_image(struct nk_context *, struct nk_image img, struct nk_vec2 size)
#define nk_vec2_len_sqr(a)
struct nk_style_button inc_button
NK_API void nk_color_d(double *r, double *g, double *b, double *a, struct nk_color)
NK_API void nk_combo_end(struct nk_context *)
NK_API int nk_propertyi(struct nk_context *, const char *name, int min, int val, int max, int step, float inc_per_pixel)
void(* draw_end)(struct nk_command_buffer *, nk_handle)
NK_API void nk_input_char(struct nk_context *, char)
NK_API void nk_color_dv(double *rgba_out, struct nk_color)
struct nk_page_element win[1]
#define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1)
NK_API struct nk_vec2 nk_vec2v(const float *xy)
NK_API int nk_tooltip_begin(struct nk_context *, float width)
NK_API struct nk_rect nk_recti(int x, int y, int w, int h)
NK_API struct nk_panel * nk_window_get_panel(struct nk_context *)
struct nk_vec2 menu_padding
struct nk_color label_normal
struct nk_style_item pressed
NK_API int nk_style_pop_color(struct nk_context *)
NK_API struct nk_color nk_rgba_iv(const int *rgba)
unsigned char single_line
struct nk_color selected_hover
NK_API void nk_chart_end(struct nk_context *)
struct nk_command_buffer * buffer
struct nk_color menu_border_color
NK_API int nk_menu_item_symbol_label(struct nk_context *, enum nk_symbol_type, const char *, nk_flags alignment)
NK_API int nk_combo_begin_symbol_label(struct nk_context *, const char *selected, enum nk_symbol_type, struct nk_vec2 size)
#define NK_ALIGN_PTR_BACK(x, mask)
NK_API int nk_style_push_vec2(struct nk_context *, struct nk_vec2 *, struct nk_vec2)
#define nk_vec2_muls(a, t)
NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context *)
NK_API int nk_menu_begin_text(struct nk_context *, const char *title, int title_len, nk_flags align, struct nk_vec2 size)
struct nk_color background
NK_API struct nk_rect nk_rectiv(const int *xywh)
struct nk_color border_color
NK_API struct nk_vec2 nk_widget_size(struct nk_context *)
NK_API void nk_layout_row_push(struct nk_context *, float value)